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

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -