jona
jona

Reputation: 31

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 ?

Upvotes: 3

Views: 3174

Answers (1)

Alvin Bunk
Alvin Bunk

Reputation: 7764

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.

Upvotes: 5

Related Questions