Note that there are some explanatory texts on larger screens.

plurals
  1. POBuild a form having a checkbox for each entity in a doctrine collection
    primarykey
    data
    text
    <p>I'm displaying an html table for a filtered collection of entities and I want to display a checkbox in each row as part of a form which will add the selected entities to a session var.</p> <p>I'm thinking that each checkbox should have the entity id as its value and I'll get an array of ids from the form field data (ok, so the value ought to be an indirect ref to the entity, but for the sake of simplicity).</p> <p>I've tried creating a form Type with a single entity type field, mapped to the id property of the entity and embedded into another form Type which has a collection type field.</p> <pre class="lang-php prettyprint-override"><code>class FooEntitySelectByIdentityType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder-&gt;add('foo_id', 'entity', array( 'required' =&gt; false, 'class' =&gt; 'MeMyBundle:FooEntity', 'property' =&gt; 'id', 'multiple' =&gt; true, 'expanded' =&gt; true )); } # ... </code></pre> <p>and</p> <pre class="lang-php prettyprint-override"><code>class FooEntitySelectionType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder-&gt;add('identity', 'collection', array( 'type' =&gt; new FooEntitySelectByIdentityType, 'options' =&gt; array( 'required' =&gt; false, 'multiple' =&gt; true, 'expanded' =&gt; true, 'attr' =&gt; array('class' =&gt; 'foo') ), )); } # ... </code></pre> <p>and in a controller the form is created with a collection of entities as the initial data</p> <pre class="lang-php prettyprint-override"><code>$form = $this -&gt;createForm( new \Me\MyBundle\Form\Type\FooEntitySelectionType, $collection_of_foo ) -&gt;createView() ; </code></pre> <p>When the form is rendered there is a single label for the identity field, but no widgets.</p> <p>Is it even possible to use entity and collection type fields in this particular way? If so, what might I be doing wrong?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload