Since Symfony 2.8, you can only pass the FQCN into the controller createForm method. So, my question is, how do I pass construct parameters into the form class construct when I create the form in the controller?
< Symfony 2.8 I could do (MyController.php):
$this->createForm(new MyForm($arg1, $arg2));
Symfony 2.8+ I can only do (MyController.php):
$this->createForm(MyForm::class);
So how can I pass in my construct arguments? These arguments are provided in the controller actions so I can't use the "Forms as services" method...
simply:
$this->createForm(MyForm::class, $entity, ['arg1' => $arg1, 'arg2' => $arg2]);
which is actually how it should have been done prior to 2.8 anyway.
edit
based upon your comment, you need to set up the default values in the class type itself:
public function configureOptions( OptionsResolver $resolver ) {
$resolver->setDefaults( [
'arg1' => null,
'arg2' => null,
] );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With