Welcome Guest, Not a member yet? Register   Sign In
RoR-like ApplicationController for CI... how?

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 Smile

[eluser]Georgi Veznev[/eluser]
you should try searching the forum for "My_Controller".

I think that it may be the answer of your question!


From another topic:
Quote:This question literally comes up daily.

Yikes! I guess you just have to know what to look for. Thanks Georgi!

[eluser]Colin Williams[/eluser]
Haha.. I think that was my line Smile

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!

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!

Theme © iAndrew 2016 - Forum software by © MyBB