找不到验证处理程序检查当前密码current_password


Could not find validation handler checkCurrentPassword for current_password

我收到这样的错误

警告 (512): 找不到验证处理程序检查当前密码 对于current_password [核心/蛋糕/模型/验证者/蛋糕验证规则.php,第 281 行]

我的用户.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'];
}

它为你工作。