title: Symfony : redirect after submit in Twig render() method
body: <p>I have a few posts in Twig view. For each post, I want to add a form comment.</p>
  
  <p>For best reusable, I call <code>render(controller())</code> in Twig.</p>
  
  <p><code>Twig</code> :</p>
  
  <pre><code>{{ render(controller('App\\Controller\\User\\PostController::comment',
      {
          'post': post,
      }
  )) }}
  </code></pre>
  
  <p><code>Controller</code> :</p>
  
  <pre><code>public function comment(Request $request, Post $post): Response
  {
      $comment = new PostComment();
      $comment-&gt;setPost($post);
  
      $form = $this-&gt;get('form.factory')-&gt;createNamedBuilder('post_comment_' . $post-&gt;getId(), PostCommentType::class, $comment)-&gt;getForm();
      $form-&gt;handleRequest($this-&gt;get('request_stack')-&gt;getMasterRequest());
  
      if ($form-&gt;isSubmitted() &amp;&amp; $form-&gt;isValid()) {
          $entityManager = $this-&gt;getDoctrine()-&gt;getManager();
          $entityManager-&gt;persist($comment);
          $entityManager-&gt;flush();
  
          $this-&gt;redirectToRoute(...); // ERROR
      }
  
      return $this-&gt;render('user/post/_comment.html.twig', [
          'form' =&gt; $form-&gt;createView(),
      ]);
  }
  </code></pre>
  
  <p>But I can't redirect after submit. I understand that it's complicated from a view, HttpRequest has already passed.</p>
  
  <p>This is error :</p>
  
  <blockquote>
    <p>An exception has been thrown during the rendering of a template ("Error when rendering "<a href="http://project.local/index.php/u/root/post" rel="nofollow noreferrer">http://project.local/index.php/u/root/post</a>" (Status code is 302).").</p>
  </blockquote>
  
  <p>Do you have a solution for me ? Thanks you :)</p>