在我的付款页面中,我只想验证所需的credit_card表单输入和cc,如果选择输入payment_type ==' credit_card'
我试过http://book.cakephp.org/3.0/en/core-libraries/validation.html#conditional-validation 在模型中虽然它在该操作中起作用但在应用程序的其他区域导致管理编辑和错误通知出错:
$validator
->add('creditcard_number', [
'cc' => [
'rule' => 'cc',
'message' => 'Please enter valid Credit Card',
'on' => function ($context) {
return $context['data']['payment_method'] == 'credit_card';
}
],
]);
有没有办法在cakephp 3中为控制器方法添加验证规则?
答案 0 :(得分:2)
最终这样做,似乎工作正常:
控制器/ OrdersController.php:
Linux basic concepts
型号/表/ OrdersTable.php:
$order = $this->Orders->patchEntity($order, $this->request->data, ['validate' => 'review']);