title: symfony2 -How to retrieve data from database globally in every page
body: <p>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?</p>
  
  <p>[Solution]</p>
  
  <p>I'm not able to respond to my topic ,I didn't have much reputation so I edit my topic</p>
  
  <p>I have found the solution, using <a href="http://symfony.com/doc/current/book/templating.html#embedding-controllers" rel="nofollow noreferrer">"embedding controllers"</a></p>
  
  <ul>
  <li><p>first I've created an action to retreive all cities names:</p>
  
  <pre><code>public function listCitiesAction(){
   // retreiving cities
  $entities = $this-&gt;getDoctrine()-&gt;getRepository("MedAdBundle:City")-&gt;findAll();
  
  return $this-&gt;render('MedAdBundle:Ville:list_cities.html.twig',
      array('entities' =&gt; $entities));
  
  }
  </code></pre></li>
  <li><p>this action render list_cities.html.twig defined as :</p>
  
  <pre><code>&lt;select class="form-control"&gt;
  {% for entity in entities %}
  &lt;option&gt;{{ entity.name}}&lt;/option&gt;
  {% endfor %}
  &lt;/select&gt;
  </code></pre></li>
  <li><p>finnaly I edit my layout.html.twig</p>
  
  <pre><code>&lt;div&gt;
  {{ render(controller('MedAdBundle:City:listCities'))}}
  &lt;/div&gt;
  </code></pre></li>
  </ul>
  
  <p>In this way I can access to cities combobox in every page in my app ;)</p>