CodeIgniter Forums
Loading models/libraries in filters? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Loading models/libraries in filters? (/thread-25086.html)



Loading models/libraries in filters? - El Forum - 11-30-2009

[eluser]behdesign[/eluser]
I'm trying to create an auth filter for my site, and I'm having trouble in loading libraries or models necessary to get the process started (mainly the session library to check for the ci_session cookie). I've tried loading the libraries directly with $this->load, but since it's not a controller, it doesn't work. I've also tried loading with $CI &= get_instance(); - also to no effect. I also have session and database in the autoload config file ... again, no joy.

How can I load libraries/helpers into a before() filter? Or what approach should I take to get an Auth filter to work?

Thanks.


Loading models/libraries in filters? - El Forum - 11-30-2009

[eluser]Colin Williams[/eluser]
What is a filter? Do you mean hook? Also, what are you trying to achieve exactly (and no, don't tell me "get access to CI" because we can see that)?


Loading models/libraries in filters? - El Forum - 11-30-2009

[eluser]behdesign[/eluser]
I've downloaded the Filters System (http://codeigniter.com/wiki/Filters_system/), and I've followed the instructions there to implement it. I want to run a check against the session to see if a user is logged in before allowing them access to certain parts of the site.


Loading models/libraries in filters? - El Forum - 11-30-2009

[eluser]behdesign[/eluser]
Is there an easier way to implement a before_filter in Codeigniter?

Edit: Ah, see now. I just read about Hooks directly. Stupid me.


Loading models/libraries in filters? - El Forum - 11-30-2009

[eluser]jedd[/eluser]
I'm painfully conscious of the old adage about 'If the only tool you have is a hammer, all your problems start to look like nails' ...

But it does sound like the filters system is scarily over-engineered for what you want to do here. Have you considered just doing this in [url="/wiki/MY_Controller"]MY_Controller[/url]?