Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm not sure what you are doing wrong here, when I build a form using form classes Symfony takes care of selecting the correct option in the list. Here's an example of one of my forms that works.</p> <p>In the controller for the edit action:</p> <pre><code>$entity = $em-&gt;getRepository('FooBarBundle:CampaignEntity')-&gt;find($id); if (!$entity) { throw $this-&gt;createNotFoundException('Unable to find CampaignEntity entity.'); } $editForm = $this-&gt;createForm(new CampaignEntityType(), $entity); $deleteForm = $this-&gt;createDeleteForm($id); return $this-&gt;render('FooBarBundle:CampaignEntity:edit.html.twig', array( 'entity' =&gt; $entity, 'edit_form' =&gt; $editForm-&gt;createView(), 'delete_form' =&gt; $deleteForm-&gt;createView(), )); </code></pre> <p>The campaign entity type class (src: Foo\BarBundle\Form\CampaignEntityType.php):</p> <pre><code>namespace Foo\BarBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use Doctrine\ORM\EntityRepository; class CampaignEntityType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder -&gt;add('store', 'entity', array('class'=&gt;'FooBarBundle:Store', 'property'=&gt;'name', 'em'=&gt;'my_non_default_em','required' =&gt; true, 'query_builder' =&gt; function(EntityRepository $er) {return $er-&gt;createQueryBuilder('s')-&gt;orderBy('s.name', 'ASC');})) -&gt;add('reward'); } public function getName() { return 'foo_barbundle_campaignentitytype'; } } </code></pre>
 

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