Sava Posted July 21, 2012 Report Posted July 21, 2012 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 4 Quote
Moderators Kyle Posted July 21, 2012 Moderators Report Posted July 21, 2012 Sava, That is an awesome tutorial, if you want, I can pin the topic for you. I don't also very see people use the docs mostly. Well Done! Quote
Sava Posted July 21, 2012 Author Report Posted July 21, 2012 Thank you very much Kyle! It means a lot coming from you! Yes that would be really nice if you can pin it! I hope it will help out a lot of new users as it took me a while to figure everything out! Quote
Moderators Parkho Posted September 3, 2012 Moderators Report Posted September 3, 2012 Great man. Well done. Quote
CPC900 Posted November 6, 2012 Report Posted November 6, 2012 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. Quote
Sava Posted November 7, 2012 Author Report Posted November 7, 2012 Yeap. Seems like I messed up the URL. Its an easy fix. I'll fix it as soon as I can. Thanks for the heads up Bruce. Appreciate it. Quote
CapitalConnectVirtualGroup Posted October 11, 2015 Report Posted October 11, 2015 Now that the later versions of PHPVMS (including 5.5.x) are using PHP instead of TPLs throughout, is it the same process and then replacing TPL with .php or? I ask purely because I am looking at upgrading and what to know whether it will affect it or not! Sorry for the basic question Quote
Moderators servetas Posted October 11, 2015 Moderators Report Posted October 11, 2015 Instead of $this->render('about.tpl'); You can use: $this->show('about'); And it will work fine with both .php and .tpl phpVMS versions. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.