1

Is it possible to call a method in controller from a model?

if ($this->db->trans_status() === TRUE)
        {
            //calling a method in controller
        }
user987654321
  • 119
  • 1
  • 1
  • 9
  • This has already been answered, here; http://stackoverflow.com/questions/9562214/access-controller-method-from-inside-a-model – Craig Apr 14 '14 at 08:50
  • Its MVC strucure.Excecute the controller method logic first and then call the model methods.If required. May be being more precise might help out here. – Nagama Inamdar Apr 14 '14 at 08:50

1 Answers1

1

If you need to do that, there's something wrong with your design. The controller is responsible for everything that happens in the view (template). But the model is responsible for manipulating and retrieving records from the database.

As a general rule, if the function is going to be used in more than one template, put it in the model. Otherwise, it goes in the controller.

The model should not know about its controllers. Maybe a redesign of your system will be more appropriate in this case.

Here is a link to similar thread.

Community
  • 1
  • 1
Nagama Inamdar
  • 2,851
  • 22
  • 39
  • 48
  • I think all the functions that are related to business logic should put in model, even the function is only used once. two reason: #1 controller should almost do nothing but passing parameters to model and pick up one view. #2 maybe the functions seem to be only used once at first, but not true later. – 尤川豪 Apr 14 '14 at 11:10