Possible Duplicate:
Constructor session validation for different functions
Framework : CI (CodeIgniter)
Situation :
I have 4 pages(controllers) namely:
home
login
dashboard
editprofile
ACCESS
home can be accessed by all types of users, logged in or not
login must be only be access if not authenticated
dashboard and editprofile must only be accessed by students(authenticated users)
I have this validatation for my controllers like this:
if($this->session->userdata('isLoggedIn')){
// stay here do the function
} else {
// leave this page
header('Location:'.base_url().'login');
}
I have that in my function index(){}
.
But as I develop the system, as i create more methods, more controllers, it's becoming messier.. for you need to use this
if($this->session->userdata('isLoggedIn')){
// stay here do the function
} else {
// leave this page
header('Location:'.base_url().'login');
}
everytime you have a method,
i've read several questions in stackoverflow... and the only best answer is this: link here
it says that i must use decorator pattern for that... but i don't clearly get how am i suppose to do that.