In CakePHP, you may want to use the Auth component to check if a user is currently logged-in to the system. you cannot access the Auth component from a view. So doing something like this in a view
$user = $this->Auth->user
This will Generate an error in CakePHP since the Auth component cannot be accessed in a view
Fortunately, there is a way to access the Auth component from a view you can simply use CakePHP Session Component. The Session component stores the the Auth component. So, if you wanted to know if a user is logged-In into the system, you can do the following:
$user = $this->Session->read('Auth.User');
if ($user){
// do something
}
0 Comment(s)