I am trying to move from codeigniter 2 to codeigniter 3. Normally in most of our functions in our controller we call other controller sometimes like this,
$this->load->controller('login');
return $this->login->index();
But in codeigniter 3 this crashes, I checked how routes worked in this stack overflow question.
How to load a controller from another controller in codeigniter?
But the above url does not work for me, since changing routes will cancel all the database trasactions I use with mysql gets cancelled.
Is there a good solution to load different controller, I thought of moving it to a library and calling it like that but I think there is a better way. Also the HMVC might be a solution but its still doesn't solve the issue for a simple purpose.
According to the link you gave you cannot do that - I am not aware of the ability to $this->load->controller
in CI3.
Your better option is to create a MY_Controller and extend your controllers from that and then place shared controller functions within that.
I think you are looking for HMVC solution. Check This Out
Update : By implementing HMVC, you can load any of your controller as a module like following
function abc(){
$this->load->module("my_auth");
$this->my_auth->check_login();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.