Welcome Guest, Not a member yet? Register   Sign In
Access control globally in controller???
#1

[eluser]mabright[/eluser]
I have a messages controller class for my website's internal private messaging system. Inside the class are functions to go to the various message folders (inbox, sent, trash, etc.).

I.e. mysite.com/member/messages/inbox equals a call to the inbox function in the messages controller.

The index function of my controller has a line for access control as follows to only allow logged in members to this area.

Code:
if($this->session->userdata('logged_in') != TRUE)
{
   redirect('member/login');
}

Do I need to add this code to each public function in my controller or can I do this globally somehow in my controller?
#2

[eluser]n0xie[/eluser]
Add them to MY_Controller or to your Controller construct(or).
#3

[eluser]mabright[/eluser]
I should have know that. I'm still wrapping my mind around OOP and CI at the same time. Thanks.
#4

[eluser]n0xie[/eluser]
No problem. Take a look here to learn some more about MY_Controller.




Theme © iAndrew 2016 - Forum software by © MyBB