First Create a base controller for the front and/or backend. Something like this:
// core/MY_Controller.php
/**
* Base Controller
*
*/
class MY_Controller extends CI_Controller {
// or MY_Controller if you use HMVC, linked above
function __construct()
{
parent::__construct();
// Load shared resources here or in autoload.php
}
}
/**
* Back end Controller
*
*/
class Admin_Controller extends MY_Controller {
function __construct()
{
parent::__construct();
// Check login, load back end dependencies
// Create and setup admin user session and other all dynamic admin url for image,js,css,etc..
}
}
/**
* Default Front-end Controller
*
*/
class Front_Controller extends MY_Controller {
function __construct()
{
parent::__construct();
// Load any front-end only dependencies
// Get user data of session and generate other all dynamic front url for image,js,css,etc..
}
}
Back end controllers will extend Admin_Controller, and front end controllers will extend Front_Controller.Now You can create any admin side controller & models and extends to Admin_Controller and front side extends to Front_Controller.
E.g (Any Admin Controller) :
class Admin extends Admin_Controller{
function __construct(){
parent::__construct();
}
}
E.g (Any Front Controller) :
class Home extends Front_Controller{
function __construct(){
parent::__construct();
}
}
Use URI routing where needed, and create separate controllers for your front end and back end side. All helpers, classes, models etc. can be shared if both the front and back end controllers live in the same application.