How can you extend class in CodeIgniter?

How can you extend class in CodeIgniter?

Team Leader Asked on June 7, 2018 in CODEIGNITER.
Add Comment
1 Answer(s)

I take it you have put your ” ____”  in /application/core, and set the prefix in the config. I would be careful about using index as a class name though. As a function/method in Codeigniter it has a dedicated behaviour.

If you then want to extend that controller you need to put the classes in the same file.

E.g. In /application core

 

/* start of php file */
class MY_Controller extends CI_Controller {
    public function __construct() {
       parent::__construct();
    }
...
}

class another_controller extends MY_Controller {
    public function __construct() {
       parent::__construct();
    }
...
}
/* end of php file */

In /application/controllers

class foo extends MY_Controller {
    public function __construct() {
       parent::__construct();
    }
...
}

or

class bar extends another_controller {
    public function __construct() {
       parent::__construct();
    }
...
}
Senior Developer Answered on July 3, 2018.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.