我正在开发Cake 3.我想创建一个自定义验证规则.
我想检查字段’password’是否等于’confirm_password’字段.
我想检查字段’password’是否等于’confirm_password’字段.
这是我的代码:
public function validationDefault(Validator $validator) { $validator ->add('id','valid',['rule' => 'numeric']) ->allowEmpty('id','create') ->add('email',['rule' => 'email']) ->requirePresence('email','create') ->notEmpty('email') ->add('email','unique',['rule' => 'validateUnique','provider' => 'table']) ->requirePresence('password','create') ->notEmpty('password') ->notEmpty('confirm_password') ->add('confirm_password','custom',[ 'rule' => function($value,$context) { if ($value !== $context['data']['password']) { return false; } return false; },'message' => 'The passwords are not equal',]); return $validator; }
我读了http://book.cakephp.org/3.0/en/core-libraries/validation.html#custom-validation-rules,但没有帮助….任何人?
谢谢!