Beginner's Question: Can I instantiate a controller from within a controller to access member functions? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22) +--- Thread: Beginner's Question: Can I instantiate a controller from within a controller to access member functions? (/showthread.php?tid=26369) |
Beginner's Question: Can I instantiate a controller from within a controller to access member functions? - El Forum - 01-12-2010 [eluser]Unknown[/eluser] Hey CI, Basically I was wondering if it would be better to create a helper for this functionality or dig to find out if the following is possible: Code: class Index extends Controller{ Thanks for your help Beginner's Question: Can I instantiate a controller from within a controller to access member functions? - El Forum - 01-12-2010 [eluser]richzilla[/eluser] Short answer - no. The simplest way around your problem as far as i can see, is to use a MY_Controller. This way you can store functions that may be used in many controllers all in one place. to do this create a MY_Controller.php file in the libraries folder of your application. Code: <?php Then have all of your controllers inherit this class: Code: <?php This way any functions in your MY_controller will also be inherited by the controller. Hope this helps. |