0
我有一个页面,我可以修改用户详细信息(用户名,名字,头像...)。 我在我的导航栏中有一个关于当前登录用户信息的元素。事情是我无法弄清楚如何在数据修改后立即刷新会话。CakePHP 3刷新会话数据
在UsersController:
public function edit($id = null)
{
if (!$id) {
throw new NotFoundException(__('Invalid user'));
}
$user = $this->Users->get($id);
if ($this->request->is(['post', 'put'])) {
$this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
//REFRESH SESSION ????\\
$this->request->session()->write('Auth.User', $user);
//\\
$this->Flash->success(__('User has been updated.'));
return $this->redirect(['action' => 'edit/' . $id]);
}
$this->Flash->error(__('Unable to update User details.'));
}
$this->set(compact('user'));
}
'unset($ data ['password'])'不应该是必须的,因为它应该位于实体内部的隐藏属性中。 –
@StefanD。在一个理想的世界中,无论烘焙功能在一个月前是否被破解(烘烤1.1.4),人们甚至可能不会使用烘焙和/或使用“token”,“password”以外的列和'passwd'(这是什么烘烤检测),所以我说它仍然值得一提的是,人们应该留意这一点。 – ndm