![]() |
RoR-like ApplicationController for CI... how? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: RoR-like ApplicationController for CI... how? (/showthread.php?tid=14702) |
RoR-like ApplicationController for CI... how? - El Forum - 01-12-2009 [eluser]oscaralexander[/eluser] I'm very new to CI but have done some RoR development in the past. RoR provides developers with a basic ApplicationController which is initialized (once, I believe) at each request. So, say you call /blog/view/my-post, it first instantiates the ApplicationController and executes whatever code you put inside its constructor. I used this controller to check whether the user is logged in and make user data available to the view, prior to executing the requested controller/action (i.e. /blog/view/my-post). This was convenient since I needed user data in 90% of the views, across different controllers. What is the CI way of doing this? Sub-classing the Controller and autoloading it? Hooks? Please help ![]() RoR-like ApplicationController for CI... how? - El Forum - 01-12-2009 [eluser]Georgi Veznev[/eluser] Hi, you should try searching the forum for "My_Controller". I think that it may be the answer of your question! Greetings! RoR-like ApplicationController for CI... how? - El Forum - 01-12-2009 [eluser]oscaralexander[/eluser] From another topic: Quote:This question literally comes up daily. Yikes! I guess you just have to know what to look for. Thanks Georgi! RoR-like ApplicationController for CI... how? - El Forum - 01-12-2009 [eluser]Colin Williams[/eluser] Haha.. I think that was my line ![]() You can also just copy system/libraries/controller.php to application/libraries/controller.php and start modifying the file. This is good if you don't need multiple parent controllers, and if you have existing controllers. Oh.. and Welcome to CI! RoR-like ApplicationController for CI... how? - El Forum - 01-12-2009 [eluser]oscaralexander[/eluser] I like keeping my files clean, so I think I'll go for the MY_Controller.php solution and just put my Application_controller there, which I'll use to extend all my other controllers. Thanks again guys! |