title: Symfony2 - How to set, and get, options when using a Form Class?
body: <p>I am using Form Classes to build the various form in my project.</p>
  
  <p>In the Entity Type file, for the buildForm function, there is a secondary parameter of "array $options" (this is shown in the official Symfony 2 Documentation, but never mentioned, ever!)</p>
  
  <p>I have fed an array into the createForm function in my controller but now I am totally stumped on how to retrieve the stored values?</p>
  
  <pre><code>$form = $this-&gt;createForm(new ProductType(array(), array('id' =&gt; '2')), $product);
  </code></pre>
  
  <p>The only thing I have found about getting the options is using the getOption() function, but that doesn't exist in Symfony 2 (the post I found was from 2010).</p>
  
  <p>I tried using:</p>
  
  <pre><code>$id = $options['id'];
  </code></pre>
  
  <p>But when I try to use $id anywhere, I get the error:</p>
  
  <blockquote>
    <p>Notice: Undefined index: id</p>
  </blockquote>
  
  <p>What gives?</p>
  
  <p>How do I retrieve my values from the $options array? Am I even setting them correctly in the first place?</p>
  
  <p>EDIT - More code:</p>
  
  <p>Form Class</p>
  
  <pre><code>&lt;?php
  
  namespace DEMO\DemoBundle\Form\Product;
  
  use Doctrine\ORM\EntityRepository;
  use Symfony\Component\Form\AbstractType;
  use Symfony\Component\Form\FormBuilder;
  
  class ProductType extends AbstractType
  {
      public function buildForm(FormBuilder $builder, array $options)
      {
          $builder
              -&gt;add('name')
              -&gt;add('slug')
              -&gt;add('reference')
              -&gt;add('description')
              -&gt;add('active_from')
              -&gt;add('active_till')
              -&gt;add('is_active')
              -&gt;add('category', 'entity', array(
                  'class' =&gt; 'DEMO\DemoBundle\Entity\Product\ProductCategory',
                  'query_builder' =&gt; function(EntityRepository $er) {
                      return $er-&gt;createQueryBuilder('u')
                          -&gt;where('u.section = :id')
                          -&gt;setParameter('id', ***ID VARIABLE NEEDS TO GO HERE***)
                          -&gt;orderBy('u.root', 'ASC')
                          -&gt;addOrderBy('u.lft', 'ASC');
                  },
                  'empty_value' =&gt; 'Choose an option',
                  'property' =&gt; 'indentedName',
              ));
      }
  
      public function getDefaultOptions()
      {
          return array(
              'data_class' =&gt; 'DEMO\DemoBundle\Entity\Product\Product'
          );
      }
  
      public function getName()
      {
          return 'demo_demobundle_product_type';
      }
  }
  </code></pre>