I have this problem in Symfony 2.8: I can't render a custom variable with my query passed to form option.
See the below code what i have tried :
This is my controller:
$form = $this->createForm('AppBundle\Form\FooAdminType', $res, array('attr' => array('fooOnes' => $Choices)));
//when $choices is my dql query
This is my formType:
public function buildForm(FormBuilderInterface $builder, array $options) {
$builder->add('bar', EntityType::class, array(
'class' => 'AppBundle:Foo',
'choices' => $options['attr']['FooOnes'],
'required' => true,
'property' => 'name',
'attr' => array(
'class' => 'col-lg-2 control-label text-center'
)
))
finally, my twig template
{% for foo in form.bar %}
{{ form_widget(foo) }}
{% endfor %}
...Without the for
block, the form is rendered. With the for
block, I have this error:
An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class Doctrine\ORM\PersistentCollection could not be converted to string") in form_div_layout.html.twig at line 277.
PS: I have defined the public function __toString()
in the entity