Welcome Guest, Not a member yet? Register   Sign In
Loading models/libraries in filters?

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?


[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)?

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.

Is there an easier way to implement a before_filter in Codeigniter?

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

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]?

Theme © iAndrew 2016 - Forum software by © MyBB