找不到 current_password 的验证处理程序 checkCurrentPassword

Could not find validation handler checkCurrentPassword for current_password

我遇到这样的错误

Warning (512): Could not find validation handler checkCurrentPassword for current_password [CORE/Cake/Model/Validator/CakeValidationRule.php, line 281]

我的User.php

public function validate_passwords() {
        return check( $this->data[$this->alias]['confirm_password'], $this->data[$this->alias]['password']);
}

您不能像这样访问 check() 因为它是一个受保护的方法

有关详细信息,请参阅:http://api.cakephp.org/3.0/class-Cake.Validation.Validation.html

你不试试下面这样的东西吗:

public function validate_passwords() {
    return array('check' => array($this->data[$this->alias]['confirm_password'], $this->data[$this->alias]['password']));

}

要使用密码验证 confirm_password 添加此规则:

$validator->add('confirm_password', 'no-misspelling', [
    'rule' => ['compareWith', 'password'],
    'message' => 'Passwords are not equal',
]);

您可以使用它来验证 confirm_password 密码

public function validate_passwords() 
{
     return $this->data[$this->alias]['password'] === $this->data[$this->alias]['confirm_password'];
}

它适合你。