CodeIgniter Forums
Call controller from another (code organization) - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Call controller from another (code organization) (/showthread.php?tid=27833)



Call controller from another (code organization) - El Forum - 02-22-2010

[eluser]albertone01[/eluser]
Hi,
i have this problem.
I have 2 controllers: home and offers.
I need to call in many functions of the home controller, a function of the offers controller.

How can I do this?
Do I have to extend the home class?
Do I have to include the offers controller file?

Tried many ways without success...

Question 2:
Is correct to call from home class the offers class or would be better to create a library?
Or something like that?

Thanks


Call controller from another (code organization) - El Forum - 02-22-2010

[eluser]heavenquake[/eluser]
It is not correct to call functions from another controller. Think of controllers as the final "layer" of abstraction before the user. The controller is the interface the user sees, and is unique for the specific action the user wishes to perform. Any code that is shared between classes should be stored in models or libraries.

In this case it sounds like you want to have the code in models, home_model and offers_model respectively.