I think you have lost a bit in the Symfony2 form collection, although I think you already read http://symfony.com/doc/current/cookbook/form/form_collections.html .
Here, I just focus on the document, help other SO readers, and work a bit on the answer to the question. :)
First, you must have at least two objects. In your case, Booking and Participant . To arrange your reservation, add the following. Since you are using Doctrine, Participant needs to be wrapped in an ArrayCollection .
use Doctrine\Common\Collections\ArrayCollection; class Booking() { // ... protected $participants; public function __construct() { $this->participants = new ArrayCollection(); } public function getParticipants() { return $this->participants; } public function setParticipants(ArrayCollection $participants) { $this->participants = $participants; } }
Secondly, your member can be anything. For instance:
class Participant { private $name; public function setName($name) { $this->name = $name; return $this; } public function getName() { return $this->name; } }
Thirdly, your reservation type should contain a ComponentType collection, something like this:
// ... $builder->add('participants', 'collection', array('type' => new ParticipantType()));
Fourth, the type of participant is simple. According to my example:
// ... $builder->add('name', 'text', array('required' => true));
Finally, in BookingController add the required number of Member to create the collection.
// ... $entity = new Booking(); $participant1 = new Participant(); $participant1->name = 'participant1'; $entity->getParticipants()->add($participant1); // add entry to ArrayCollection $participant2 = new Participant(); $participant2->name = 'participant2'; $entity->getParticipants()->add($participant2); // add entry to ArrayCollection