Welcome Guest, Not a member yet? Register   Sign In
Best practice in getting session information to be used by many methods
#1

[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!






Messages In This Thread
Best practice in getting session information to be used by many methods - by El Forum - 11-24-2011, 08:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB