cakephp3验证函数根据相同形式的字段

时间:2016-02-18 14:48:40

标签: php model-view-controller cakephp-3.0

嘿伙计们,我在cakephp 3模型中需要帮助

我正在尝试验证表单中的数据。我想要做的是检查模式的值,但我需要验证函数来检查类型,并相应地选择模式与

进行比较
public function validationDefault(Validator $validator)
{
    return $validator
        ->add('name', [
            'notBlank' => [
                'rule' => 'notBlank',
                'message' => (__('Name should not be empty'))
            ],
            'maxlength' => [
                'rule' => ['maxLength', 100],
                'message' => (__('Name should be at most 100 characters long'))
            ]
        ])
        ->add('type', [
            'inList' => [
                'rule' => ['inList', ['hotLine', 'phoneNumber']],
                'message' => (__('The type must be available in the types list'))
            ]
        ])
        ->add('value', [
            'checkType' => [
                'rule' => function ($value, $context) {

                },
                'message' => (__('The value does not match the type you chose'))
            ]
        ]);
}

规则函数应根据上面字段中选择的类型(hotLine或phoneNumber)检查数据是否有效

非常感谢您的帮助

顺便说一句,如果我做错了,请指出

提前致谢

0 个答案:

没有答案