I have an entity "ticket" and I would like to create a form with many of this entity.
So I created a FormType like this :
class TicketType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('quantity');
}
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => null,
));
}
public function getName()
{
return 'event';
}
}
And here my controller :
$clientTickets = array();
for ($i = 0; $i < 5; $i++) {
clientTickets[] = new Ticket();
}
$formTickets = $this->createForm(new TicketType(), array('tickets' => $clientTickets));
if ($request->getMethod() == 'POST') {
$formTickets->handleRequest($request);
for ($i=0; $i < $formTickets.size(); $i++) {
$em->persist($ticket[$i]);
}
}
And finally my twig :
{{ form_start(form, {'attr': {'class': 'form-horizontal', 'id': 'msform', 'name': 'myform', 'method': 'POST' }}) }}
{% for clientTicket in form.tickets %}
{{ form_widget(form.quantity) }}
{% endfor %}
{{ form_rest(form) }}
{{ form_end(form) }}
When I go on the page, I get this error :
Method "tickets" for object "Symfony\Component\Form\FormView" does not exist in YourBundle:folder:view.html.twi at line
Why did I do wrong ? Have you got a solution ?