Cake 1.2 Auth – Is someone logged in?

The Auth login stores the user information in the Session  (with Auth  key). The Auth->user() is actually a wrapper function to the session  Auth.User key. The Auth logout function delete the informations from the session.


The Auth login stores the user information in the Session  (with Auth  key). The Auth->user() is actually a wrapper function to the session  Auth.User key. The Auth logout function delete the informations from the session.

Knowing this, you can use the Session component in controllers and the session helper in views to detect the login status.

in controllers:

$this->Session->check(‘Auth.User.id’) will return true if the user is  logged, you can also use $this->Auth->user(‘id’).

in views

$session->check(‘Auth.User.id’) will tell you if a user is logged, and you can user $session->read(‘Auth.User’) to retrieve the user’s information.

Credits

Leave a Reply

Your email address will not be published. Required fields are marked *