Authentication check for admin website |
[eluser]deed02392[/eluser]
Hi guys. I'm creating a web application where every single page load would require the user is authenticated. So far I have just been including an 'is_logged_in' check for every single method of all the controller classes but this seems like madness. Is there somewhere in the framework which supports authenticating the user on a higher level, such that I can simply assume the user is authenticated if one of my controllers is loaded? Thanks!
[eluser]CroNiX[/eluser]
Create a MY_Controller and have all of your other controllers extend that instead of CI_Controller. In the construct of MY_Controller you can put your auth. http://ellislab.com/codeigniter/user-gui...asses.html
[eluser]deed02392[/eluser]
Hmm on this point, what about defining common information like the logged in username and user ID? I guess the best place to declare this is in the constructor of MY_Controller, but then it isn't accessible to the views when they're called in. What can I do about that?
[eluser]CroNiX[/eluser]
$this->load_vars($data) makes it available to all views
[eluser]deed02392[/eluser]
Looks like that's undocumented, do you mean to use it in the controller to specify it as a global or to set $data elements in the controller and use Code: $this->load_vars($data)
[eluser]Aken[/eluser]
It's documented in the Loader Class. Except it would be $this->load->vars($data). You'd call it in your controller.
[eluser]Mauricio de Abreu Antunes[/eluser]
Save those informations in sessions. |
Welcome Guest, Not a member yet? Register Sign In |