[eluser]Zorancho[/eluser]
First thing, create new file at application/libraries folder and name it MY_Controller.php
If you want to change the prefix MY, go to application/config/config.php file, on line 106 you got this: $config['subclass_prefix'] = 'MY_'; which means you can add your own subclass prefix.
You need this when you extend core classes from CI.
In MY(or whatever your prefix is)_Controller.php file, create new class.
Code:
//This is parent of all of your controllers from application/controllers folder.
class MY(or whatever your prefix is)_Controller extends Controller
{
//You will execute parent's constructor and inherit all of its methods.
function __construct()
{
parent::__construct();
}
//All methods here can be used in your controllers like: $this->sharedFunction();
public function sharedFunction()
{
echo 'I am available in all of your controllers';
}
}
//You can create one parent for the front controllers.
class Front_Controller extends MY(or whatever your prefix is)_Controller
{
public function __construct()
{
parent::__construct();
}
public function frontFunction()
{
echo 'I am available in all of your front controllers';
}
}
//One for the admin part in the same file.
class Admin_Controller extends MY(or whatever your prefix is)_Controller
{
public function __construct()
{
parent::__construct();
}
public function adminFunction()
{
echo 'I am available in all of your admin controllers';
}
}
Then in your application/controllers/home.php
Code:
class Home extends Front_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->frontFunction();
}
}
In your application/controllers/admin/dashboard.php
Code:
class Dashboard extends Admin_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->adminFunction();
}
}
Hope it helps