我想刷新我正在编辑的用户的会话,因此他不需要注销以获取新的详细信息,例如角色。
我的编辑功能是:
public function edit($id = null)
{
if (!$id) {
$this->Flash->error(__('User not found.'));
}
$user = $this->Users->get($id);
if ($this->request->is(['post', 'put'])) {
$this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($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'));
}
我怎样才能做到这一点?感谢。
答案 0 :(得分:0)
您可以尝试这样的事情:
public function edit($id = null)
{
if (!$id) {
$this->Flash->error(__('User not found.'));
}
$user = $this->Users->get($id);
if ($this->request->is(['post', 'put'])) {
$this->Users->patchEntity($user, $this->request->data);
if ($this->Users->save($user)) {
$this->Flash->success(__('User has been updated.'));
$this->request->session()->write([Auth.YourUserVariable => $user]);
return $this->redirect(['action' => 'edit/' . $id]);
}
$this->Flash->error(__('Unable to update User details.'));
}
$this->set(compact('user'));
}
然后当你的用户提升他/她的个人资料如果它保存用户它会覆盖会话,你使用Auth确定吗?要查看用户的详细信息,您可以尝试:
debug($this->request->session()->read('Auth'));exit;
或类似的东西;)