when I update data in the User model, the Auth data is not updated.
How can I \"refresh\" the data which is returned by $this->Auth->user() when I am updating user model
I think func0der's answer is good, but it may be improved:
protected function renewLogin() {
if(!empty($this->Auth->user())) {
$this->loadModel('User');
$this->User->contain(false);
$user = $this->User->read(null, $this->Auth->user('id'))['User'];
unset($user['password']);
$this->Auth->login($user);
}
}
You can add this to your AppController.php and use it from any controller after modifying the logged in user.
I believe it's much cleaner and even though it implies access to the database, I think it's not going to be executed often enough to be an issue.
You should ALWAYS try to do things the "Cake" way. And avoid shortcuts like editing a session variable. It'll make things easier for you on the long run.
Please comment and add your opinions :)