Answer the question
In order to leave comments, you need to log in
How to create a checkbox form from an array of objects?
Hello everyone, I can not understand how the forms work.
I'm trying to create a form that would generate a checkbox sheet.
The data comes from the repository:
$paginatedUsers = $userRepository->getAll($paginated, $userArt, $this->getUser())->getQuery()->getResult();
//простой массив с объектами
[
0 => App\Entity\User\User
1 => App\Entity\User\User
2 => App\Entity\User\User
]
$builder
->add('user', CollectionType::class, [
'entry_type' => ListType::class,
'allow_add' => true,
'allow_delete' => true,
'prototype' => true,
'label' => false,
'by_reference' => false
])
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('id', CheckboxType::class, [
'label' => false,
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
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