5.2.5.9 user
user(string $key = null)
This method provides information about the currently authenticated user. The information is taken from the session. For example:
if ($this->Auth->user('role') == 'admin') {
// Do something
}
if ($this->Auth->user('role') == 'admin') {// Do something}
It can also be used to return the whole user session data like so:
$data['User'] = $this->Auth->user();
$data['User'] = $this->Auth->user();
If this method returns null, the user is not logged in.
In the view you can use the Session helper to retrieve the currently authenticated user's information:
$this->Session->read('Auth.User'); // returns complete user record
$this->Session->read('Auth.User.first_name') //returns particular field value
$this->Session->read('Auth.User'); // returns complete user record$this->Session->read('Auth.User.first_name') //returns particular field value
The session key can be different depending on which model Auth is configured to use. Eg. If you use model Account instead of User, then the session key would be Auth.Account


























