0

我有这种方法在控制器(UsersController.php)中更改用户密码:

public function changepass() {
    if($this->User->exists()) {         
        $new_pass = $this->request->data['User']['newpass'];
        $repeat_pass = $this->request->data['User']['newrepeat'];
            if($new_pass == $repeat_pass) {
                $this->User->saveField('password',$new_pass);
                $this->Session->flash(__('Updated successfully'));
                $this->redirect(array('controller' => 'users','action' => 'dashboard'));
            } else {
                $this->Session->flash(__('Passwords did not match'));
                $this->redirect(array('controller' => 'users','action' => 'changepass'));
            }

    }
}

这个观点(changepass.ctp):

<?php 
    echo $this->Form->create();

    echo $this->Form->input('newpass',array('type'=>'text','label'=>array('text'=>'Enter new password'))); 

    echo $this->Form->input('newrepeat',array('type'=>'text','label'=>array('text'=>'Confirm new password'))); 
?>

    <button type="submit">Save</button>

<?php echo $this->Form->end(); ?>

但这似乎不起作用,我实际上无法理解为什么。你能帮助我吗?你知道这里有什么问题吗?

提前谢谢你们!

4

1 回答 1

2

在检查用户是否存在之前尝试设置用户 ID

假设您正在尝试更改当前登录用户的密码并假设您的用户 id 列被命名user_id

$this->User->id = $this->Auth->user('user_id');

如果您能具体说明一下它为什么不起作用(它是否显示密码与消息不匹配等)会更容易

于 2013-07-16T15:38:24.637 回答