如何匹配cakephp中数据库中不存在的字段

如何匹配cakephp中数据库中不存在的字段,cakephp,controllers,Cakephp,Controllers,当新密码和确认密码字段不在数据库中时,如何匹配它们 嗨。。。我想知道如何匹配我的字段“new_password”和“confirm_password”,它们不存储在数据库中,只是用于更改密码模块中的匹配目的 我试过了,但没用: if($this->data['User']['new_password'] != $this->data['User']['confirm_password'] ) { $this->Session->setFlash("New passwo

当新密码和确认密码字段不在数据库中时,如何匹配它们

嗨。。。我想知道如何匹配我的字段“new_password”和“confirm_password”,它们不存储在数据库中,只是用于更改密码模块中的匹配目的

我试过了,但没用:

if($this->data['User']['new_password'] != $this->data['User']['confirm_password'] ) {
  $this->Session->setFlash("New password and Confirm password field do not match");
} else {
  $this->data['User']['password'] = $this->data['User']['new_password'];
  $this->data['User']['id'] = $this->User->id;

  if($this->User->save($this->data)) {
    $this->Session->setFlash("Password updated");
    $this->redirect('/users/login');
  }
}
您可以尝试以下方法:

// check for empty value

if( !empty( $this->data['User']['new_password'] ) && !empty( $this->data['User']['confirm_password'] ) ) {

   if( $this->data['User']['new_password'] != $this->data['User']['confirm_password']) {

       $this->Session->setFlash("New password and Confirm password field do not match");

   } else {

       $this->data['User']['password'] = $this->data['User']['new_password'];
       $this->data['User']['id'] = $this->User->id;

       if( $this->User->save($this->data) ) {

          $this->Session->setFlash("Password updated");
          $this->redirect('/users/login');

       } else {

          $this->Session->setFlash('Password update fail');

       }
   }

} else {

   $this->Session->setFlash('Enter New password and Confirm password');

}

你说“没用”是什么意思?您是否收到任何错误?工作正常,但新密码和确认密码匹配未发生。。。。无论字段是否填充相同的数据,它都会更新后端的密码。您是否使用
debug
检查
$this->data
的内容?