'redirectToRoute' with query Parameters - Symfony2

Asked

Viewed 58 times

0

I have a route /curso/{slug} which makes a 301 redirect to another route. That route /curso/{slug} can receive some parameters per query (example: /curso/{slug}?query=1234), but redirect to the other route using return $this->redirectToRoute('nova_rota', array('slug' => $slug), these query parameters are lost. How can I add the query parameters in this redirect.

Code block that redirects to the other route:

    /**
     * @Route("/{slug}", name="course_show")
     */
    public function showAction(Request $request, $slug)
    {

        return $this->redirectToRoute('redirect_slug', array('slug' => $slug));
    }
  • Already tried $this->redirectToRoute('redirect_slug', array('Slug' => $Slug, 'query' => 123))

  • 1

    You can use $request->request->all() to take the parameters and merge an array with the second parameter passed in redirectToRoute, so it will dynamically take all the parameters and send in redirect tb.

  • It worked, thanks. If you want, put as answer to the question, so I mark as solved...

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.