Cakephp 3.x
我想自定义我的验证码验证,但我无法访问会话。
$validator->notEmpty('securityCode', __('not empty message'))
->add('securityCode','custom',
['rule' => function ($value, $context) use ($extra) {
if($this->request->Session()->read('captcha') != $value) {
return false;
}
return true;
}, 'message' => 'error security code']);
return $validator;
我可以给自定义验证函数提供自定义参数吗?
public function validationLogin(Validator $validator, $customParameter)
{ //bla bla }
我使用:http://book.cakephp.org/3.0/zh-cn/core-libraries/validation.html#自定义验证规则