0
我想验证一个数组使用验证组,因为一些条件,但验证组似乎不影响数组?Symfony2数组验证组
$params = [
'type' => 'a',
'province' => 'b',
'district' => 'c'
];
$constraints = new Collection([
'type' => [new NotBlank()],
'province' => [new NotBlank(['groups' => ['selection']])],
'district' => [new NotBlank(['groups' => ['selection']])],
'distance' => [new NotBlank(['groups' => ['location']])],
'lat' => [new NotBlank(['groups' => ['location']])],
'lon' => [new NotBlank(['groups' => ['location']])],
]);
$errors = $this->container->get('validator')->validate($params, $constraints, ['selection']);
验证错误:
Array[distance]:
This field is missing. (code 1)
Array[lat]:
This field is missing. (code 1)
Array[lon]:
This field is missing. (code 1)
感谢您的帮助!