[eluser]Unknown[/eluser]
Hi people,
Let say at my controller named Book, I have many methods, such as get_book(), read_book(), remove_book(), etc.
No methods in the class can be used without user logged in, and I can get the user_id from session.
My question is,
what is/are the best ways to check the if the user_id session is set so that I can use the methods?
As for now I am thinking of creating a is_logged_in() method, and apply it to every methods with an if-else statement, like
Code:
if($this->is_logged_in()
{
//do something
}
else
{
//redirect to home
}
Isn't it long and tedious? Is there an ultimate way to achieve this?
Thank you for helping me!