phpformssymfony

Add custom options to a form


I'd like to pass an option to my form so I did this:

$builder->add('pays', 'collection', array(
        'type' => new PaysType(),
        'em' => $this->em,
        'allow_add' => true,
    )
);

Although I added em to my form PaysType I got this error: he option "em" does not exist

  public function getDefaultOptions(array $options)
  {
      $options = parent::getDefaultOptions($options);
      $options['em'] = '';
      return $em;
  }

Any ideas?


Solution

  • getDefaultOptions() should return the options array but you are returning $em. I think that may be your only problem.