I want to retrieve Cities names from a table in the database and put them as options in a select input (combobox) which is defined in 'layout.html.twig' . All my views extends 'layout.html.twig', so how can I access to cities names in every page?
[Solution]
I'm not able to respond to my topic ,I didn't have much reputation so I edit my topic
I have found the solution, using "embedding controllers"
first I've created an action to retreive all cities names:
public function listCitiesAction(){ // retreiving cities $entities = $this->getDoctrine()->getRepository("MedAdBundle:City")->findAll(); return $this->render('MedAdBundle:Ville:list_cities.html.twig', array('entities' => $entities)); }
this action render list_cities.html.twig defined as :
<select class="form-control"> {% for entity in entities %} <option>{{ entity.name}}</option> {% endfor %} </select>
finnaly I edit my layout.html.twig
<div> {{ render(controller('MedAdBundle:City:listCities'))}} </div>
In this way I can access to cities combobox in every page in my app ;)