Refresh array of user sessions after editing CAKEPHP information

I would like to know how I can reload the array (Auth.User) after the user has updated his information.

At the moment, this will not happen until the user logs out and logs in when he loads the array (Auth.User).

So far I have tried several solutions for example .

I also tried adding $user = $this->User->field('name', array('User.id' => $this->Session->read('Auth.User.id'))); $this->Session->write('Auth.User', $user); $user = $this->User->field('name', array('User.id' => $this->Session->read('Auth.User.id'))); $this->Session->write('Auth.User', $user); to the application controller.

But not one of them was successful.

thanks

+4
source share
1 answer

You are just there. Remember that the returned $user array contains the User key, for example:

 array( 'User' => array( 'id' => 1 ) ) 

Thus, saving it in a session under Auth.User actually save the session array as follows:

 array( 'Auth' => array( 'User' => array( 'User' => array( 'id' => 1 ) ) ) ) 

Instead, save it in the Auth key, and you can continue to access it as usual:

 $user = $this->User->field('name', array( 'User.id' => $this->Session->read('Auth.User.id') )); $this->Session->write('Auth', $user); 

Now that the session keys are cleared, there is a much simpler and faster way to re-enter the user’s system, as mark says in the comments: use $this->Auth->login() .

 $user = $this->User->field('name', array( 'User.id' => $this->Session->read('Auth.User.id') )); $this->Auth->login($user); 
+6
source

All Articles