Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony 3, how to transfer URL parameters with redirectToRoute method

I use redirectToRoute in my controller, and i want to know how can i transfer URL parameters in this method (redirectToRoute) ?

I already search on the web (SF documentation and forums), but i didn't find the solution.

Thanks.

like image 996
C. Thubert Avatar asked Jul 25 '16 07:07

C. Thubert


1 Answers

Let's look into source of this method:

/**
 * Returns a RedirectResponse to the given route with the given parameters.
 *
 * @param string $route      The name of the route
 * @param array  $parameters An array of parameters
 * @param int    $status     The status code to use for the Response
 *
 * @return RedirectResponse
 */
protected function redirectToRoute($route, array $parameters = array(), $status = 302)
{
    return $this->redirect($this->generateUrl($route, $parameters), $status);
}

As you can see the second argument is $parameters.

So simply pass them as an array as second argument. So it should be used like:

$this->redirectToRoute('show_page', array('id' => 123));
like image 70
Jakub Matczak Avatar answered Nov 08 '22 19:11

Jakub Matczak