我无法制定验证规则

时间:2016-01-29 12:33:11

标签: php cakephp cakephp-3.0

我只想在值不为NULL时检查值。

$validator->add('sort_order', 'valid', [
    'rule' => 'numeric',
    'message' => Configure::read('errorMessage.numericOnly'),
    'on' => function ($context) {
        return !empty($context['data']['sort_order']);
    }
]);

我尝试使用此代码但不起作用。

"This field cannot be left empty"< - 当值为NULL时显示此消息。

哪里错了?

$validator
    ->add('sort_order', 'valid', ['rule' => 'numeric', 'message' => 'numericOnly'])
    ->allowEmpty('sort_order');

我也试试这个。 它没用。 输入非数字值时,不显示错误消息。

0 个答案:

没有答案