Я хочу использовать form_widget для визуализации поля для формы collectionType.Вот мой контроллер:
/**
* @Route("/ticket", name="ticket")
*/
public function ticket(Request $request)
{
$data = $request->getSession()->get('orders');
$number = $data->getNumberOfTickets();
for ($i=1; $i<=$number ;$i++){
$tickets[] = new Tickets();
}
$form = $this->createForm(CollectionType::class, $tickets, ['entry_type' => TicketsType::class] );
$form->handleRequest($request);
dump($request);
return $this->render('louvre/ticket.html.twig', [
'tickets' =>$tickets,
'form' => $form->createView()
]);
}
и когда я пытаюсь:
{{ form_widget(tickets.firstname)}}
или
{{ form_widget(form.firstname)}}
или
{{ form_widget(form.tickets.firstname)}}
У меня естьошибка:
Ни свойство "firstname", ни один из методов "firstname ()", "getfirstname ()" / "isfirstname ()" / "hasfirstname ()" или "__call () "существуют и имеют открытый доступ в классе" Symfony \ Component \ Form \ FormView ".
Вот моя форма:
class TicketsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('category', CheckboxType::class, [
'attr' => [
'class' => 'form-control'
]
])
->add('firstname', TextType::class, [
'attr' => [
'class' => 'form-control'
]
])
->add('lastname', TextType::class, [
'attr' => [
'class' => 'form-control'
]
])
->add('country', TextType::class, [
'attr' => [
'class' => 'form-control'
]
])
->add('dateOfBirth', DateType::class, [
'attr' => [
'class' => 'form-control'
],
'widget' => 'single_text',
])
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Tickets::class,
]);
}
}