title: symfony2 - adding choices from database
body: <p>I am looking to populate a choice box in symfony2 with values from a custom query.  I have tried to simplify as much as possible.</p>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>class PageController extends Controller
  {
  
      public function indexAction()
      {
        $fields = $this-&gt;get('fields');
        $countries =  $fields-&gt;getCountries(); // returns a array of countries e.g. array('UK', 'France', 'etc')
        $routeSetup = new RouteSetup(); // this is the entity
        $routeSetup-&gt;setCountries($countries); // sets the array of countries
  
        $chooseRouteForm = $this-&gt;createForm(new ChooseRouteForm(), $routeSetup);
  
  
        return $this-&gt;render('ExampleBundle:Page:index.html.twig', array(
          'form' =&gt; $chooseRouteForm-&gt;createView()
        ));
  
      }
  }
  </code></pre>
  
  <p><strong>ChooseRouteForm</strong></p>
  
  <pre><code>class ChooseRouteForm extends AbstractType
  {
  
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
  
      // errors... ideally I want this to fetch the items from the $routeSetup object 
      $builder-&gt;add('countries', 'choice', array(
        'choices' =&gt; $this-&gt;routeSetup-&gt;getCountries()
      ));
  
    }
  
    public function getName()
    {
      return 'choose_route';
    }
  }
  </code></pre>