cakephp 2.0 how to update auth data?

后端 未结 7 1509
别那么骄傲
别那么骄傲 2021-02-01 08:12

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

7条回答
  •  名媛妹妹
    2021-02-01 08:26

    I solved this problem using afterSave function in User Model. It's working fine if we update user model from any area. My code was as below :

    class User extends AppModel {
        ... ... ...
        public function afterSave($created, $options = array()){
            parent::afterSave($created,$options);
    
            //updating authentication session
            App::uses('CakeSession', 'Model/Datasource');
            CakeSession::write('Auth',$this->findById(AuthComponent::user('id')));
    
            return true;
        }
        ... ... ...
    }
    

提交回复
热议问题