php - Use function to add choices to select form Symfony 2 -


i'm developping symfony application (v2.8) 2 main bundles : easyadmin , fosuserbundle.

i have users particular role , i'm using 'findby' array retrieve users.

i override form of admin controller fill select form choices users. know it's possible array want dynamic if add or delete users.

i don't know how can call function 1 of controllers (or have declare service ?) add choices select form query.

here example of :

$formbuilder->add('field_to_override', 'choice', array(    'choices' => **my_function**,    'multiple' => true,    'expanded' => true, )); 

i hope i'm clear in explanation.

thank in advance !

consider using entitytype field, specialized form of choice field uses doctrine entities choices.

it possible specify custom query choices too, e.g.

$builder->add('users', entitytype::class, array(     'class' => 'appbundle:user',     'query_builder' => function (entityrepository $er) {         return $er->createquerybuilder('u')             ->orderby('u.username', 'asc');     }, )); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -