title: Symfony: how to get a parameter from the route within a FormType?
body: <p>I'm trying to access the parameter <code>page</code> from the current route within a <code>FormType</code>. It works in a <code>Controller</code>, but not in a <code>FormType</code>. I'd like to avoid passing the parameter like <code>/?page=1</code> and prefer <code>/page/1</code>.</p>
  
  <p><strong>routing.yml</strong></p>
  
  <pre><code>my_route:
      path: /data/page/{page}
      defaults:
          _controller: MyBundle:MyController:myAction
  </code></pre>
  
  <p><strong>src/myBundle/Form/Type/MyFormType.php</strong></p>
  
  <pre><code>class MyFormType extends AbstractType {
      // ...
      public function buildForm(FormBuilderInterface $builder, array $options) {
          $request = Request::createFromGlobals();
          $page    = $request-&gt;query-&gt;get('page');
          echo "page: $page"; // empty
  
          // ...
      }
  }
  </code></pre>
  
  <p>I'd like to avoid to pass the parameter through the Controller to the FormType and prefer to access it directly within the FormType.</p>
  
  <p>Any ideas?</p>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Edit:</strong> 
  Regarding the selected answer; the <code>page</code> <strong>attribute</strong> is accessible via <code>$request-&gt;attributes-&gt;get('page')</code>, not via <code>$request-&gt;query-&gt;get('page')</code>.</p>