2

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');

    }
}
1
  • 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'); } } Commented Jan 30, 2019 at 11:24

2 Answers 2

2

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:

  1. /application/core/MY_Controller.php and extend that class
  2. Move the behaviour to a model
  3. Move the behaviour to a library or helper

If you are unfamiliar with the MVC pattern, this forum post might help you. It's from an old thread, but the principles still apply.

Sign up to request clarification or add additional context in comments.

Comments

1

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.