public function editMe()
{
// fetch current identity data
$user = $this->Authentication->getIdentity()->getOriginalData();
if ($this->request->is(['patch', 'post', 'put'])) {
$user = $this->Users->patchEntity($user, $this->getRequest()->getData());
if ($this->Users->save($user)) {
$this->Authentication->setIdentity($user); // ----- > update identity data
$this->Flash->success(__('The user has been saved.'));
return $this->redirect(['action' => 'me']);
}
$this->Flash->error(__('The user could not be saved. Please try again.'));
}
$this->set(compact('user'));
}
1条答案
按热度按时间klr1opcd1#
如何@ CakePHP 4.x
更新身份对象:
$this->Authentication->setIdentity($user);
完整示例: