title: Display empty form collection item in Symfony without using javascript
body: <p>I'm trying to display a form with a collection. The collection should display an empty sub-form. Due to the projects nature I can't rely on JavaScript to do so. </p>
  
  <p>Googling didn't help and I does not seem to work by adding an empty entity to the collection field.</p>
  
  <p>What I have so far:</p>
  
  <pre><code>public function indexAction($id)
  {
      $em = $this-&gt;getDoctrine()-&gt;getManager();
      $event = $em-&gt;getRepository('EventBundle:EventDynamicForm')-&gt;find($id);
  
      $entity = new Booking();
      $entity-&gt;addParticipant( new Participant() );
      $form   = $this-&gt;createForm(new BookingType(), $entity);
  
      return array(
          'event' =&gt; $event,
          'edit_form' =&gt; $form-&gt;createView()
      );
  }
  </code></pre>
  
  <p>In BookingType.php buildForm()</p>
  
  <pre><code>$builder
      -&gt;add('Participants', 'collection')
  </code></pre>
  
  <p>In the Twig template</p>
  
  <pre><code>{{ form_row(edit_form.Participants.0.companyName) }}
  </code></pre>
  
  <p>If I put the line $entity->addParticipant( new Participant() ); in indexAction() I get an error saying:</p>
  
  <blockquote>
    <p>The form's view data is expected to be of type scalar, array or an
    instance of \ArrayAccess, but is an instance of class
    Yanic\EventBundle\Entity\Participant. You can avoid this error by
    setting the "data_class" option to
    "Yanic\EventBundle\Entity\Participant" or by adding a view transformer
    that transforms an instance of class
    Yanic\EventBundle\Entity\Participant to scalar, array or an instance
    of \ArrayAccess.</p>
  </blockquote>
  
  <p>If I delete the said line Twig complains:</p>
  
  <blockquote>
    <p>Method "0" for object "Symfony\Component\Form\FormView" does not exist in
    /Applications/MAMP/htdocs/symfony-standard-2.1/src/Yanic/EventBundle/Resources/views/Booking/index.html.twig
    at line 27</p>
  </blockquote>
  
  <p>EDIT: The addParticipant is the default methos generated by the doctrine:generate:entities command</p>
  
  <pre><code>/**
   * Add Participants
   *
   * @param \Yanic\EventBundle\Entity\Participant $participants
   * @return Booking
   */
   public function addParticipant(\Yanic\EventBundle\Entity\Participant $participants)
   {
       $this-&gt;Participants[] = $participants;
  
       return $this;
   }
  </code></pre>
  
  <p>I'm sure that I'm doing something wrong, but can't find the clue :-(</p>