Best place to check if logged-in |
[eluser]Craig Ward[/eluser]
Currently I use the following for checking is a user is logged in: Code: function only_a_loggedin_user_can_do_this() Whats the best way to achieve what I want but in a more simplistic way that is easier to update. I was thinking of the below, Code: function check_if_logged_in() www.example.com/index.php/check_if_logged_in/only_a_logged-in_user_can_do_this/ Whats the best way to implement this?
[eluser]danmontgomery[/eluser]
Code: class Some_controller extends CI_Controller { I would probably put something like that in a base controller, however, assuming it would need to be used across multiple controllers.
[eluser]JuanitoDelCielo[/eluser]
My favorite way it's extend the CI_Controller class adding the method and it will be avaliable to every single controller.
[eluser]JuanitoDelCielo[/eluser]
I found it again http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
[eluser]lalouze78[/eluser]
You also can use a pre-controller hook with a CI_Controller extended class. This method allow you to check if user is logged in and change directly controller and method called without use a redirect() like function.
[eluser]mdvaldosta[/eluser]
Extend the base controller and put the check in there, that way it doesn't have to be duplicated for every controller. Just like Sturgeon's article suggests. |
Welcome Guest, Not a member yet? Register Sign In |