当我试图实现以下目标时:
我这样做的方法如下:
<?php
echo $form->create('User', array('action' => 'changeEmail'));
echo $form->input('email');
echo $form->end('Change');
?>
然后我的控制器
function changeEmail(){
if(!empty($this->data)){
$user = $this->Auth->user();
$user['User']['email'] = $this->data['User']['email'];
$activationcode = _generateActivationCode();
$user['User']['activationcode'] = $activationcode;
$user['User']['isactive'] = false;
if($this->User->save($user)){
//sendmail
}
}
然后我会看到他们可以激活电子邮件的视图,我会执行以下操作:
function activate(){
$user = $this->Auth->user();
//Now this variable doesn't reflect the changes we've just saved (for example the activationCode)
}
这是预期的行为还是我在这里做错了什么。
答案 0 :(得分:6)
AuthComponent在会话中缓存用户数据。在用户再次登录之前,不会刷新此数据。您可以明确地覆盖会话中的数据:
$this->Session->write('Auth.User', $user);
或者重新验证用户,这应该提示刷新(如果这确实有效的话,不要100%确定我的头顶):
$this->Auth->login($this->Auth->user('id'));