Hi, Make your form class a service prototype and then you can inject anything you want and retrieve instances of the form from DIC. Essentially the DIC becomes your form factory.
- Jon On Thu, Mar 3, 2011 at 9:48 PM, Jan Eichhorn <j...@pixel-web.org> wrote: > Hi, > > actually i want to add an "Dynamic" Choice Field to a Form Object. > This choices array("a" => "b") comes from a Service wich i've registered > before. > > So i need to get access to this service. > $options = $container->get('mysevice')->getOptions(); > > $this->add('options', new ChoiceField('status', array( > 'choices' => $options, > 'required' => false, > )); > > But how im going to do this? I Need Access to "myservice" here. But the > Formobject dosen't provide anything like this. > > So i override the contructor to add an option of concreteContext. > > class WallForm extends Form > { > protected $concreteContext; > > public function __construct($name = null, array $options = array()) > { > $this->addOption('concreteContext'); > > $this->concreteContext = $options['concreteContext']; > > parent::__construct($name, $options); > } > > /*** > } > > In the Controller i could use this: > > $form = WallForm::create($this->get('form.context'), 'wall_new', > array('concreteContext' => $this)); > > Is there a better way to do this? > > -- > If you want to report a vulnerability issue on symfony, please send it to > security at symfony-project.com > > You received this message because you are subscribed to the Google > Groups "symfony users" group. > To post to this group, send email to symfony-users@googlegroups.com > To unsubscribe from this group, send email to > symfony-users+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/symfony-users?hl=en > -- Connect with me on *http://twitter.com/jwage* <http://twitter.com/jwage> and http://about.me/jwage to keep in touch. -- If you want to report a vulnerability issue on symfony, please send it to security at symfony-project.com You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to symfony-users@googlegroups.com To unsubscribe from this group, send email to symfony-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en