我在我的 UsersController.php 文件中创建了一个方法,以便我的用户可以更改他们的密码。我的方法php代码是:
public function changepass() {
$this->User->id = $this->Auth->user('id');
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->setFlash(__('Updated successfully'));
$this->redirect(array('controller' => 'users','action' => 'dashboard'));
} else {
$this->Session->setFlash(__('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(); ?>
当我尝试在 users/changepass 下浏览时,它返回了 2 个关于未定义索引的错误:
Notice (8): Undefined index: User [APP/Controller/UsersController.php, line 108]
Notice (8): Undefined index: User [APP/Controller/UsersController.php, line 109]
指向我的代码的这一部分:
$new_pass = $this->request->data['User']['newpass'];
$repeat_pass = $this->request->data['User']['newrepeat'];
而且它(立即)将我数据库中的用户密码更改为空白。
我无法以任何方式找出问题所在。如果您能在这一点上帮助我,我将不胜感激。
先感谢您。