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)
感謝您的幫助!