'Symfony :how do you pass an array (result of a query from the database), from the controller to the form and build a drop down menu

I have a form and i need to pass it an array. This array is the result of a query from my repository.

I need to build a drop down menu (with a ChoiceType::class, [ 'choices' => $array['code']...

Q1: how do you pass the array (to the form from the controller)?

Q2: how do you retrieve the 'code' field and use it in the choices of my form?

Q3: do you have an example for this ?

Tried different things but nothing is working...need some help. Thank you.



Solution 1:[1]

enter image description herei have found myslef the solution. The Symfony doc is not really helpfull when creating a dynamic customised choice menu (drop down list). I had to use the $options and to dig dip to find the solution. I am happy because the choices are dynamic and they are linked to the Library that is selected when connecting to the site.enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 SGuirous