Are we allowed to call a controller from another controller in Codeigniter?
9 answers. You can’t load a controller from a controller in CI, unless you use HMVC or something. You should think a bit about your architecture. If you need to call a controller method from another controller, then you should probably abstract that code to a helper or library and call it from both controllers.
Table of Contents
How to pass data from one controller to another in Codeigniter?
In Codeigniter there are many ways to pass the value from one controller to another. You can use Codeigniter Session to pass data from one controller to another controller. $this->load->library(‘session’); You can then set the value of the flash data using the variable name.
How do I extend my CI controller?
As a function/method in Codeigniter it has a dedicated behavior. If you later want to extend that controller, you have to put the classes in the same file. class foo extends MY_Controller { public function __construct() { parent::__construct(); } }
What is base controller in CodeIgniter?
codeigniter-base-controller is an extended class of CI_Controller for use in your CodeIgniter applications. Any controller that inherits from MY_Controller gets smart view autoloading, layout support, and asides/partials.
What is the difference between MVC and HMVC?
While MVC has only one controller per request, HMVC can have more than one controller, combining with many triads. By allowing reuse of existing code, it makes it easy to test disparate parts of systems while ensuring application improvement.
How to call another controller’s method in CodeIgniter?
You can then return that string and pass it to the other controller’s view. You can load in a string by adding true to the end of the view call – a very simple way in codeigniter to call a method from one controller to another controller 1.
How to call one controller function in another?
I have a controller called home.php in which there is a function called podetails. I want to call this function in another user.php controller. Is this possible to do? I have read about HMVC in CI, but I want to know if it is possible to do it without using hmvc. To extend the controller follow this tutorial or see the code below.
How do you extend a controller in Java?
To extend the controller follow this tutorial or see the code below. also note that all the variables that should be used in the view are in this variable (array) $this->data writes the details() as a function inside a help file. then load that helper in both controllers.
How to load a controller from another controller?
From your controller call method(‘name’) to load the controller. Note that name is the driver file name. This method will add ‘_controller’ to your controller ‘name’. To call a method on the controller just run $this->name_controller->method (); after loading the driver as described above.