title: How to get an id from url in Symfony
body: <p>So I have an url like this: localhost:8000/answer/create?id=254.</p>
  <p>The full way to get is: localhost:8000/questions -&gt; localhost:8000/questions/{question_id} -&gt; localhost:8000/answer/create?id=254.</p>
  <p>How to make an app read this id=254 as a question_id?</p>
  <p>Part of Controller:</p>
  <pre><code>    /**
       * Create action.
       *
       * @param \Symfony\Component\HttpFoundation\Request $request          HTTP request
       * @param \App\Repository\AnswerRepository          $answerRepository Answer repository
       *
       * @return \Symfony\Component\HttpFoundation\Response HTTP response
       *
       * @throws \Doctrine\ORM\ORMException
       * @throws \Doctrine\ORM\OptimisticLockException
       *
       * @Route(
       *     &quot;/create&quot;,
       *     methods={&quot;GET&quot;, &quot;POST&quot;},
       *     name=&quot;answer_create&quot;,
       * )
       */
      public function create(Request $request, AnswerRepository $answerRepository): Response
      {
          $answer = new Answer();
          $form = $this-&gt;createForm(AnswerType::class, $answer);
          $form-&gt;handleRequest($request);
  
          if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
              $answerRepository-&gt;save($answer);
              $this-&gt;addFlash('success', 'answer_created_successfully');
  
              return $this-&gt;redirectToRoute('answer_index');
          }
  
          return $this-&gt;render(
              'answer/create.html.twig',
              ['form' =&gt; $form-&gt;createView(),
                  'question_id' =&gt; $answer, ]
          );
      }
  
  </code></pre>
  <p>And template with form:</p>
  <pre><code>{% extends 'base.html.twig' %}
  
  {% block title %}
      {{ 'title_answer_create'|trans ({'%id%': answer.id|default('')})}}
  {% endblock %}
  
  {% block body %}
      &lt;h1&gt;{{ 'title_answer_create'|trans }}&lt;/h1&gt;
      {{ form_start(form, { method: 'POST', action: url('answer_create') }) }}
      {{ form_widget(form) }}
      &lt;div class=&quot;form-group row float-sm-right&quot;&gt;
          &lt;input type=&quot;submit&quot; value=&quot;{{ 'action_save'|trans }}&quot; class=&quot;btn btn-primary&quot; /&gt;
      &lt;/div&gt;
      &lt;div class=&quot;form-group row float-sm-left&quot;&gt;
          &lt;a href=&quot;{{ url('question_index') }}&quot; class=&quot;btn btn-link&quot;&gt;
              {{ 'action_back_to_list'|trans }}
          &lt;/a&gt;
      &lt;/div&gt;
      {{ form_end(form) }}
  {% endblock %}
  </code></pre>