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

[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 Smile
#2

[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!
#3

[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!
#4

[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!
#5

[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!




Theme © iAndrew 2016 - Forum software by © MyBB