title: How to get query string from a search input in Symfony2
body: <p>Once the user submits his search text from the input box, the goal is to show the search results in an url like this:</p>
  
  <pre><code>www.foo.com/search/&lt;query_string&gt;
  </code></pre>
  
  <p>Here is the html from the twig template:</p>
  
  <pre><code>&lt;form 
      class="navbar-form" 
      method="get" 
      action="{{ path('path_id', {'searchTerm': app.request.query.get('search-term')}) }}" 
      role="search"&gt;
      &lt;div class="input-group"&gt;
          &lt;input type="search" class="form-control" placeholder="Search" name="search-term" id="search-term" required&gt;
          &lt;div class="input-group-btn"&gt;
              &lt;button class="btn btn-default" type="submit"&gt;&lt;i class="glyphicon glyphicon-search"&gt;&lt;/i&gt;&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Here is the route I've created in the controller:</p>
  
  <pre><code>/**
   * @Route("/search/{searchTerm}", defaults={"searchTerm" = null})
   * @Template()
   */
  public function searchAction($searchTerm)
  {
      return array('searchTerm' =&gt; $searchTerm);
  }
  </code></pre>
  
  <p>I've set the search term to default to null, because if I don't do that, it gives an error message, since the <code>app.request.query.get</code> in the twig template it's not set if the user has not yet made a search.</p>
  
  <p>The problem with this approach is that <code>$searchTerm</code> always arrives null in the <code>searchAction</code>, even when the user performs a search, and I don't know exactly why is this the case.</p>
  
  <p>Any ideas how to fix this?</p>
  
  <p>If this is in general a wrong approach in order to show search results, I would be thankful if someone could point me to a better solution. Bear in mind that I cannot use doctrine in this proyect because I have to use a cloud database, so I don't think a search engine bundle would work in this case.</p>