I have successfully extended the CI_Controller class by creating a MY_Controller.php which I have placed in the application/core directory.
core/My_Controlle
All files in the folder application/core
class MY_Controller extends CI_Controller
{
public function __construct()
{
parent::__construct();
echo "This is " . __CLASS__ . "
";
}
}
Public
class Public_Controller extends My_Controller
{
public function __construct()
{
parent::__construct();
echo "This is " . __CLASS__ . "
";
}
}
Dashboard have 2 subclasses, Admin and User
class Dashboard_Controller extends My_Controller
{
public function __construct()
{
parent::__construct();
echo "This is " . __CLASS__ . "
";
}
}
Admin
class Admin_Controller extends Dashboard_Controller
{
public function __construct()
{
parent::__construct();
echo "This is " . __CLASS__ . "
";
}
}
User
class User_Controller extends Dashboard_Controller
{
public function __construct()
{
parent::__construct();
echo "This is " . __CLASS__ . "
";
}
}
in config/config.php
/* load class in core folder */
function my_load($class) {
if (strpos($class, 'CI_') !== 0) {
if (is_readable(APPPATH . 'core' . DIRECTORY_SEPARATOR . $class . '.php' )) {
require_once (APPPATH . 'core' . DIRECTORY_SEPARATOR . $class . '.php');
}
}
}
spl_autoload_register('my_load');
in controller/Home.php
//class Home extends MY_Controller {
//class Home extends Dashboard_Controller {
class Home extends Admin_Controller {
public function index()
{
echo "This is " . __CLASS__ . "
";
//$this->load->view('home');
}
}