1

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

if ($this->db->trans_status() === TRUE)
        {
            //calling a method in controller
        }
2
  • This has already been answered, here; stackoverflow.com/questions/9562214/… Commented Apr 14, 2014 at 8: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. Commented Apr 14, 2014 at 8:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.