Answer the question
In order to leave comments, you need to log in
Why does the error "This value should be of type array." occur?
The form has a "categories" field:
->add('categories', EntityType::class, [
'choices' => $categories,
'choice_label' => function (Category $category = null) {
return null !== $category ? str_repeat('--', $category->getLevel()).' '.$category->getTitle() : '';
},
'choice_value' => function (Category $category = null) {
return null !== $category ? $category->getId() : '';
},
'class' => Category::class,
'constraints' => [
new Assert\Choice([
'choices' => $categories,
'multipleMessage' => 'Выберите разделы из предложенного списка.',
'multiple' => true,
]),
],
'label' => 'Разделы',
'multiple' => true,
])
if ($form->isSubmitted()) {
echo gettype($_POST['categories']); // Выводит "array"
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question