I want to create two parent controllers: one for admin and one for user site. They have to extend a regular Controller class but each of them has to do different things.
相关问题
- Views base64 encoded blob in HTML with PHP
- how to define constructor for Python's new Nam
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Keeping track of variable instances
This is pretty easy. Do the following:
your_ci_app/application/core/
and create a php file calledMY_Controller.php
(this file will be where your top parent classes will reside)Open
MY_Controller.php
and add your multiple classes, like so:Create your children controllers under this directory
your_ci_app/application/controllers/
. I will call itadminchild.php
Open
adminchild.php
and create your controller code, make sure to extend the name of the parent class, like so:I wrote up an article showing how you do this.
http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY
You need to create an __autoload() function in your config.php or directly include the base controller above the class definition.