title: How do I obtain all the GET parameters on Silex?
body: <p>I've been using Silex for a day, and I have the first "stupid" question. If I have:</p>
  
  <pre><code>$app-&gt;get('/cities/{city_id}.json', function(Request $request, $city_id) use($app) {
      ....
  })
  -&gt;bind('city')
  -&gt;middleware($checkHash);
  </code></pre>
  
  <p>I want to get all the parameters (city_id) included in the middleware:</p>
  
  <pre><code>$checkHash = function (Request $request) use ($app) {
  
      // not loading city_id, just the parameter after the ?
      $params = $request-&gt;query-&gt;all();
  
      ....
  }
  </code></pre>
  
  <p>So, how do I get city_id (both the parameter name and its value) inside the middleware. I'm going to have like 30 actions, so I need something usable and maintainable.</p>
  
  <p>What am I missing?</p>
  
  <p>thanks a lot!</p>
  
  <p><strong>Solution</strong></p>
  
  <p>We need to get those extra parameters of <em>$request->attributes</em></p>
  
  <pre><code>$checkHash = function (Request $request) use ($app) {
  
      // GET params
      $params = $request-&gt;query-&gt;all();
  
      // Params which are on the PATH_INFO
      foreach ( $request-&gt;attributes as $key =&gt; $val )
      {
          // on the attributes ParamaterBag there are other parameters
          // which start with a _parametername. We don't want them.
          if ( strpos($key, '_') != 0 )
          {
              $params[ $key ] = $val;
          }
      }
  
      // now we have all the parameters of the url on $params
  
      ...
  
  });
  </code></pre>