I want to call a function in a controller (say controller_a) from another controller (say controller_b)
Please help me ..
Defining a Default ControllerCodeIgniter can be told to load a default controller when a URI is not present, as will be the case when only your site root URL is requested. To specify a default controller, open your application/config/routes. php file and set this variable: $route['default_controller'] = ' Blog ';
A controller is the intermediary between models and views to process HTTP request and generates a web page. All the requests received by the controller are passed on to models and views to process the information. It is the center of every request on your web application.
In terms of codeigniter: You'll notice that each controller in codeigniter extends the base controller class. Using $this in a controller gives you access to everything which is defined in your controller, as well as what's inherited from the base controller.
Constructor is a function that is automatically called when instantiated. this function helps us to intialize the things that we are going to need frequently in our code like when we have to load the models of helpers like form e.t.c.
Shared controller functions should usually be in an extended controller class:
<?php
/**
* File: /application/core/MY_Controller.php
*/
class MY_Controller extends CI_Controller {
/**
* Prefix with an underscore if you don't want it
* publicly available through URI-routing
*/
public function _some_shared_method()
{
// some common operation here
}
}
Then, make sure any controller that needs to use this function extends MY_Controller
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With