Welcome Guest, Not a member yet? Register   Sign In
Isn't there "Filters" in CI?
#1

[eluser]Skyblaze[/eluser]
I see that there isn't "Filters" (special functions that are executed at specific times before every method/function in the controller) in CI. If i have to put some code that tests if an user is authenticated (watching the session) for all the methods/pages in the controller i know that i can put that code in the controller constructor but that is limited. Like so i can only run that code for all the methods in the controller but what if i want it executes only for ceratin methods? Then in the constructor i can put only one type of code.....if i have to run also another piece of code for all the methods?
#2

[eluser]johnwbaxter[/eluser]
http://ellislab.com/codeigniter/user-gui...hooks.html

I think this is what you're looking for.

Using "Hook Points" you can run your code at pretty much any point in the app flow.

Good Luck!
#3

[eluser]Skyblaze[/eluser]
yes i knew that but that is the same as putting the code in the constructor so the ode will run for every method of the controller class.....what if i want to run my code only for certain methods?
#4

[eluser]Pascal Kriete[/eluser]
Most authentication libraries have a procedure similar to this when checking if a user is logged in:
Code:
$this->load->library('auth');
$this->auth->checkLogin();

Now if you want to protect specific methods, you put the first line in your constructor and the second line at the beginning of every protected method. It depends on what auth lib you're using though.




Theme © iAndrew 2016 - Forum software by © MyBB