Jump to content

Developing Custom Pages/Modules and MVC


Sava

Recommended Posts

Some people asked me how do I create the custom modules/pages (however you would like to call them )

For example the recruitment page ( http://www.airserbia...php/recruitment )

It is actually really easy but for people who are new with PHP and MVC pattern ( like me not long ago ) it can be quite challenging to understand.

First off, there is good documentation on this matter but not many people take a look there unfortunately.

First of, MVC.

The MVC pattern is really easy to describe. You 'separate' your code in three different sections/files.

Models, Views, Controllers (MVC)

Models are in charge for work with the database, the views are what are displayed to the end user and the controllers control the entire 'application'.

Controllers

About

In phpVMS, which is developed on the Codon Framework, all controllers are located in the following directory.

 /core/modules/<module name> 

http://www.myva.com/index.php/something

routes to the index function of the respective controller located

core/modules/Something/Something.php

(More on this later)

Naming

All folders should be named with the first letter in uppercase. The controller itself should also be named with the first letter in uppercase. Lets take an example

For example, the controller for the Profile is located here:

/core/modules/Profile 

and contains the file Profile.php which is the controller.

Views

About

The views are located in the core/templates folder. They contain the HTML output shown to the end user. Any logic should be in the controller not the view file.

Naming

All views belonging to a single module should be named with the module name first followed by an _ and a description of the view's purpose.

For example mymodule_showeverything or mymodule_newsomething.

Models

About

The models are located in the core/common directory. They are the database layer and handle all requests to the database.

Naming

Models and are named with the first letter in uppercase. The models end with .class.php (SiteData.class.php).

----------------------------------------------------------------------

So, we covered that, let's go to the actual creating of our first module. Let's use the About Us page for example.

Create a new folder inside the

core/modules directory

.Name it About and create a new php file inside called About.php

Once completed, the About.php file should look like this:

<?php
class About extends CodonModule
{
function index ()
{
$this->render('about.tpl');
}
function mission ()
{
$this->render('about_mission.tpl');
}

}
?>

Let's take a look what we have done here

First of we extend the CodonModule and create a new index function. This is the function that is loaded when no further functions are appended to the url.

Inside that function we call the view with the $this->render() command. If your view is located in a subfolder you need to add that ( ex. $this->render('subfolder/view.tpl') )

Than we have the mission function which loads the respective view file and can be found with this link: /index.php/about/mission

This is the basic concept to get you up and running.

Please do take a look at the documentation for more information!

http://forum.phpvms....and-add-ons-r25

http://forum.phpvms....conventions-r17

  • Like 4
Link to comment
Share on other sites

  • 1 month later...
  • 2 months later...

Sava, just so you know, I went to your site http://www.airserbiavirtual.com/index.php/recruitment and selected "Continue", and then on the next page under "If you have read the requiremets and the recruitment page please proceed and fill out your application." I selected recruitment page link to go back, and I got this:

[b]Warning[/b]: call_user_func_array() [[url="http://www.airserbiavirtual.com/index.php/recruitment/site_url/index.php/recruitment/function.call-user-func-array"]function.call-user-func-array[/url]]: First argument is expected to be a valid callback, 'Recruitment::site_url' was given in [b]/home/skysim/public_html/airserbia/core/classes/MainController.class.php[/b] on line [b]218[/b]

Most people would NOT do that but for some reasoin I did :) Just thought I would mention it.

Link to comment
Share on other sites

  • 1 year later...
  • 1 year later...
  • 9 months later...
  • 11 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...