[eluser]Michael Ekoka[/eluser]
Using base controlles provides you with great amount of flexibility, this is what MVC and OO programming is about. You don't have to create your base controllers in application/libraries/MY_Controller.php, you can move them and later include them there. Even if you want to package your code I don't see how this can be a problem.
Code:
Package
|-controllers
|- admin
|- login.php
|- management.php
|- forms.php
|- site
|- registration.php
|-libraries
|-Base_controllers
|- All_Base_Controllers.php (this file would include all the others)
|- Admin_Controller.php
|- Application_Controller.php
If you drop the content of such a package in a CI application it will fall right in place. The only extra step you might need would be to connect the Base controllers to your application and this can be done in a simple step:
In your application/libraries/MY_Controller.php, just include the All_Base_Controllers.php file (which itself includes the others). Alternatively you can decide to simply include your base controllers at the top of your controllers files if you wish to make everything automatic for someone using your release.
in application/libraries/MY_Controller.php
Code:
include_once 'Base_Controllers/All_Base_Controllers.php';
in application/controllers/admin/management.php
Code:
// optional. Use this if you don't want to include your Base controllers from the MY_Controller.php file
include_once APPPATH.'libraries/Base_Controllers/All_Base_Controllers.php';
What would your base controllers look like: e.g. your Admin_controller.php would have something like this:
Code:
class Admin_controller extends Controller{
function __construct(){
// some init steps
if(!this->_authenticate())redirect('admin/login');
parent::__construct();
// additional init steps (set language, db connect, authentication, cookies collect, etc)
}
private function _authenticate(){
// if logged in session variable is set return true, else return false
}
...
}
Then your controllers would just extend the base they need to and be ready to use:
controllers/admin/management.php
Code:
class Management extends Admin_controller{
...
}
controllers/admin/forms.php
Code:
class Forms extends Admin_controller{
...
}
controllers/admin/login.php
Code:
class Login extends Controller{
function index(){
// if username/password match, set the logged in session variable to true
// else show login screen again
}
...
}
controllers/site/registration.php
Code:
class Registration extends Application_controller{
...
}