title: Symfony2: How to pass url querystring parameters to controllers?
body: <p>Maybe I am missing something but there doesn't seem to be a way to define querystring parameters in routes in Symfony2 so that they can be passed into a controller. </p>
  
  <p>For instance, instead of generating a URI like <code>/blog/my-blog-post</code> (from Symfony2's <a href="http://symfony.com/doc/master/book/routing.html">routing documentation</a>) and passing it to the following route:</p>
  
  <pre><code># app/config/routing.yml    
  blog_show:
      pattern:   /blog/{slug}
      defaults:  { _controller: AcmeBlogBundle:Blog:show }
  </code></pre>
  
  <p>I would prefer to generate a URI like <code>/blog?slug=my-blog-post</code>. The problem is I can't find anywhere to define the <code>slug</code> parameter in the route configuration file (like its {slug} counterpart above).</p>
  
  <p>Perhaps this is on purpose but then what is the best practice for working with GET parameters in the querystring?</p>
  
  <p>The documentation does make mention of them in <a href="http://symfony.com/doc/master/book/routing.html#generating-urls-with-query-strings">Generating URLs with Query Strings</a>, so how to pass them into the controller?</p>
  
  <p>Where I can find mention of them is <a href="http://symfony.com/doc/current/book/http_fundamentals.html">Symfony2 and HTTP Fundamentals</a>:</p>
  
  <pre><code>use Symfony\Component\HttpFoundation\Request;
  
  $request = Request::createFromGlobals();
  
  // retrieve GET variables
  $request-&gt;query-&gt;get('foo');
  </code></pre>
  
  <p>Is this the best practice for working with them inside the controller?</p>