Access controller method from inside a model Access controller method from inside a model codeigniter codeigniter

Access controller method from inside a model


You don't.

Although it is technically possible, if you think that you need to, it suggests a flaw in your application's design.

The Controller layer is the backbone of you application and meant to handle requests from the user, talk to the Model layer, and stitch together the output in the View. Your Model layer should be blind to the Controller and View, but deal with data manipulation only. This is an over-simplified explanation of the MVC pattern (you can find resources for that elsewhere).

Your Codeigniter models should be reusable from any controller, and not dependent on them. There are many solutions to solve whatever problem it is that you have: You can pass data into a model in a number of ways, or you can use the result of a call to a model's method to perform an action in your Controller.


You can use like this:

class some_model extends Model{   function getController()   {   $controllerInstance = & get_instance();   $controllerData = $controllerInstance->getData();   }}