【发布时间】:2015-10-18 18:15:05
【问题描述】:
我正在尝试使用comparison rule,但似乎遗漏了什么或做得不对。基本上我需要的是验证以检查 small_size 的值是否小于或等于 big_size。
但这不起作用,无论大小如何,目前都会出现错误。
在表格中:
...
$validator
->add('small_size', 'valid', ['rule' => 'numeric'])
->requirePresence('small_size', 'create')
->notEmpty('small_size')
->add('small_size', 'comparison', [
'rule' => ['comparison', 'big_size', '<='],
'message' => 'Small size cannot be more than the Big size.'
]);
return $validator;
}
public function buildRules(RulesChecker $rules)
{
$rules->add($rules->existsIn(['Entity_id'], 'Entity'));
return $rules;
}
我们将不胜感激。
【问题讨论】:
-
@Holt 回答,您需要查看自定义验证:book.cakephp.org/3.0/en/core-libraries/…
标签: php validation cakephp cakephp-3.0 comparison-operators