The Controller is the "C" in MVC. The base controller is a simple abstract class that defines the structure of all controllers. By including the registry here, the registry is available to all class that extend from the base controller. An index() method has also been included in the base controller which means all controller classes that extend from it must have an index() method themselves.

Add this code to the controller.class.php file in the application directory.

<?php
Abstract Class baseController {
protected $registry;
function __construct($registry) {
   $this->registry = $registry;
}
abstract function index();
}
?>

Whilst we are in the controller creating mood, we can create an index controller and a blog controller. The index controller is the system default and it is from here that the first page is loaded. The blog controller is for an imaginary blog module. When the module is specified in the URL

http://www.example.com/blog

then the index method in the blog controller is called. A view method will also be created in the blog controller and when specified in the URL

http://www.example.com/blog/view

then the view method in the blog controller will be loaded. First lets see the index controller. This will reside in the controller directory


<?php
class indexController extends baseController {
public function index() {
$this->registry->template->welcome = 'Welcome to MindPHP.com';
$this->registry->template->show('index');
}
}
?>

The indexController class above shows that the indexController extends the baseController class, thereby making the registry available to it without the need for global variables. The indexController class also contains the mandatory index() method that ll controllers must have. Within itn index() method a variable named "welcome" is set in the registry. This variable is available to the template when it is loaded via the template->show() method.

The blogController class follows the same format but has one small addition, a view() method. The view() method is an example of how a method other than the index() method may be called. The view method is loaded view URL http://www.example.com/blog/view

<?php
Class blogController Extends baseController {
public function index(){
$this->registry->template->blog_heading = 'This is the blog index';
$this->registry->template->show('blog_index');
}
public function view() {
$this->registry->template->blog_heading = 'This is the blog heading';
$this->registry->template->blog_content = 'This is the blog content';
$this->registry->template->show('blog_view');
}
}
?>

 

Recent Topics
Subject
Post Reply
Open
Recent
Show Products Category by Module Category
By prmindphp Tue 24 Mar 2020 6:07 pm Board English Language
0
4934
Tue 24 Mar 2020 6:07 pm By prmindphp View Topic Show Products Category by Module Category
Plugin System MZC Auto Close to enable the open and close odering system
By prmindphp Wed 19 Feb 2020 6:38 pm Board English Language
0
5799
Wed 19 Feb 2020 6:38 pm By prmindphp View Topic Plugin System MZC Auto Close to enable the open and close odering system
MDPartner Component for store client data in CRM system
By prmindphp Sat 25 Jan 2020 3:04 pm Board English Language
0
2217
Sat 25 Jan 2020 3:04 pm By prmindphp View Topic MDPartner Component for store client data in CRM system
i am looking for help
By Anonymous Tue 14 Jan 2020 5:46 pm Board English Language
1
2178
Tue 14 Jan 2020 6:03 pm By noppadonsk View Topic i am looking for help
Dot Net Training
By Poonaam Fri 10 Jan 2020 2:20 pm Board English Language
0
2545
Fri 10 Jan 2020 2:20 pm By Poonaam View Topic Dot Net Training
MDRental, Area management assistant for rental business
By prmindphp Wed 08 Jan 2020 6:51 pm Board English Language
0
2013
Wed 08 Jan 2020 6:51 pm By prmindphp View Topic MDRental, Area management assistant for rental business
Fix Gmail Error 404 By Taking Gmail Help Quickly
By Anonymous Wed 08 Jan 2020 2:56 pm Board English Language
0
3258
Wed 08 Jan 2020 2:56 pm By Anonymous View Topic Fix Gmail Error 404 By Taking Gmail Help Quickly
How To Add New Facebook Friends using Facebook Phone Number?
By Anonymous Tue 07 Jan 2020 4:20 pm Board English Language
0
2215
Tue 07 Jan 2020 4:20 pm By Anonymous View Topic How To Add New Facebook Friends using Facebook Phone Number?
DBA Training Institute
By Shrutiii Wed 01 Jan 2020 3:06 pm Board English Language
0
1488
Wed 01 Jan 2020 3:06 pm By Shrutiii View Topic DBA Training Institute
Tools for calculating the withholding tax easily reduce large tax
By prmindphp Wed 25 Dec 2019 6:56 pm Board English Language
0
2240
Wed 25 Dec 2019 6:56 pm By prmindphp View Topic Tools for calculating the withholding tax easily reduce large tax
Helper to calculate interest rates for investors
By prmindphp Tue 24 Dec 2019 6:52 pm Board English Language
0
1490
Tue 24 Dec 2019 6:52 pm By prmindphp View Topic Helper to calculate interest rates for investors
Plan your savings easily with FV (Future Value) Calculator
By prmindphp Mon 23 Dec 2019 7:28 pm Board English Language
0
1744
Mon 23 Dec 2019 7:28 pm By prmindphp View Topic Plan your savings easily with FV (Future Value) Calculator
Payment Calculator, Installment calculation to make decisions
By prmindphp Fri 20 Dec 2019 6:00 pm Board English Language
0
1571
Fri 20 Dec 2019 6:00 pm By prmindphp View Topic Payment Calculator, Installment calculation to make decisions
Program Calculate Home Loan, Tools that will help you calculate home loans easily and quickly
By prmindphp Thu 19 Dec 2019 6:59 pm Board English Language
0
3210
Thu 19 Dec 2019 6:59 pm By prmindphp View Topic Program Calculate Home Loan, Tools that will help you calculate home loans easily and quickly
The website loads slowly ? The image size is not proportional, MImageoptimize Plugin of Joomla can help
By prmindphp Tue 17 Dec 2019 7:05 pm Board English Language
0
1267
Tue 17 Dec 2019 7:05 pm By prmindphp View Topic The website loads slowly ? The image size is not proportional, MImageoptimize Plugin of Joomla can help
Calculation program Number of Periods (NPER)
By prmindphp Mon 16 Dec 2019 7:21 pm Board English Language
0
1822
Mon 16 Dec 2019 7:21 pm By prmindphp View Topic Calculation program Number of Periods (NPER)
Calculation program after including VAT
By prmindphp Fri 13 Dec 2019 5:32 pm Board English Language
0
2860
Fri 13 Dec 2019 5:32 pm By prmindphp View Topic Calculation program after including VAT
Plugin Content MChangelog ,helps add content that has changed, update, and fix the problem
By prmindphp Thu 12 Dec 2019 6:46 pm Board English Language
0
1559
Thu 12 Dec 2019 6:46 pm By prmindphp View Topic Plugin Content MChangelog ,helps add content that has changed, update, and fix the problem
Pace Calculator
By prmindphp Wed 11 Dec 2019 6:53 pm Board English Language
0
1679
Wed 11 Dec 2019 6:53 pm By prmindphp View Topic Pace Calculator
Introducing to MooZiiCart's Coupons feature, create coupons on website sell products online it is certain to boost sales
By prmindphp Mon 09 Dec 2019 11:06 am Board English Language
0
2312
Mon 09 Dec 2019 11:06 am By prmindphp View Topic Introducing to MooZiiCart's Coupons feature, create coupons on website sell products online it is certain to boost sales