目前想使用codeigniter4框架对下面的数据进行验证
[{"departmentId":100},{"percentage":10,"departmentId":10}]
验证用的代码如下
$validationService->setRules([
'costDepartment.*.departmentId' => [
'rules'=>'required|is_natural_no_zero',
'errors' => [
'required' => '必须填写',
'is_natural_no_zero' => '非0值',
]
],
'costDepartment.*.percentage' => [
'rules'=>'required|is_natural_no_zero|less_than_equal_to[100]',
'errors'=>[
'required' => '必须填写',
'is_natural_no_zero' => '非0值',
'less_than_equal_to' => '值小于等于{param}',
]
],
]);
目前对于上述组合来说,运行后是不会得到任何错误的,但我希望是costDepartment的每个元素都对departmentId和percentage进行相应的检查,即按照上述测试用例应该会告诉我有percentage是需要填写的,请问这个需要怎么进行修改,谢谢。
看了一下源码,无解,只能自己写外挂解决。