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 ?
and I don't want to use
$this->Auth->login($data);
after updating my user table
evert0ns answer is right. But you should use AuthComponent::login(), because the data is saved within the AuthComponent as well and is not fetched from the session every time.
I had the problem just a couple of days ago.
Source: my paste
Put this in your AppController. The method is specialized to merge the current and the new user data to keep existing custom indexes that you may have provided. I needed this, but you can leave it out though. Give the updated user data as a parameter to the method. Not in model find form. E.g.:
Write the updated data to the Session eg:
Before CakePHP 2.x you can't do this in the model without break the framework design.
With CakePHP 2.x you can load the Session Component from models and update it.
I think func0der's answer is good, but it may be improved:
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 :)
I tried the following line. Its works well form me After modify the user data i written the following line
I solved this problem using
afterSave
function inUser
Model. It's working fine if we update user model from any area. My code was as below :I think that the simpler way to do this is: