Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing redirection not working properly (Symfony 3)

I have an issue with my application, I have several routes declared on my controller which works properly but I have trouble with one of them.

I used the annotation system to declare the route of this method (like all my routes which works) like this :

/**
 * Do something
 *
 * @Route("/synchro", name="app_synchro")
 */
public function synchroAction(Request $request){
    //code here etc...
}

I checked it with the debug:router command so I know this route exists, I also tried to print $route and the value is good but when I made a redirection using :

return $this->redirectToRoute('app_synchro');

I encounter a 404 error.

Please, could someone help me to understand the origin of this issue ?

like image 591
jona Avatar asked Dec 03 '25 23:12

jona


1 Answers

The proper way to redirect is to return it directly like so:

return $this->redirectToRoute('my_route_name');

What you are doing is returning the result code of redirecting...

$route= $this->redirectToRoute('my_route_name');

So $route contains the result of the redirect, which is NOT what you want.

like image 67
Alvin Bunk Avatar answered Dec 06 '25 03:12

Alvin Bunk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!