Please wait for 15 seconds...

Friday 27 July 2012

There are many libraries that you commonly initialize in every controller in codeigniter, so you load them one by one in every controller. But if you load these libraries in My_Controller you can call library methods in every controller. So lets get start it.

First create My_Controller class in application/core.

Remember filename must be MY_Controller.php else codeigniter will throw some error.

Now extend Codeigniter's main controller(CI_Controller), so we can use its properties and methods in My_Controller class

class MY_Controller extends CI_Controller{
    public function __construct(){
        $this->load->library('session'); // loading session class
        $this->load->library('my_custom_library'); // loading library class

Now we are ready to extent MY_Controller in other controllers.

class Home extends MY_Controller{
    public function index(){

*You can also change MY_ prefix through config.

Happy coding..

Posted by Atul


Post a Comment

Techsirius on Facebook