Thursday, March 3, 2016

Extending multiple controllers in Code Igniter

Hi! If you are forced to use old framework like codeigniter, and want to have multiple base controllers and then extend them here a trick you can do:

1) check the value of
$config['subclass_prefix'] = 'MY_';
in application\config\config.php
By default it is MY_ ; but nvm check to make sure.
2) create php file called MY_Controller.php (or your %prefix%Controller.php inside application\core folder
3) In this file (MY_Controller.php) you can create any amount of base controllers that extends CI_Controller, and then in simple controllers extend these base controllers
<?phpif (!defined('BASEPATH')) {    exit('No direct script access allowed');}

class Admin_Controller extends CI_Controller{    }
class Public_Controller extends CI_Controller{
}

No comments:

Post a Comment