Reputation: 595
How to load more than one controller in another controller in CodeIgniter. The below code is i'm using. But it doesn't working. Only the controller which specified at first was work the second one is not working.
class A extends CI_Controller{
function __construct(){
parent::__construct();
$this->load->controller('B');
$this->load->controller('C');
}
}
Upvotes: 2
Views: 763
Reputation: 1478
You shouldn't be loading other controllers. Each request should be handled by a single controller. If you require common behaviour you have the following options:
/application/core/MY_Controller.php
and extend that classIf you are unfamiliar with the MVC pattern, this forum post might help you. It's from an old thread, but the principles still apply.
Upvotes: 2
Reputation: 2943
There are various methods to do that. One of them: you can try this.
//Load the controller you want
$this->load->library('../controllers/controller_name');
//and can call functions of that controller
$this->controller_name->function_name();
I hope this is helpful!
Upvotes: 1