Symfony: how to redirect to homepage after logout

I presented a symfony pre-build project in which the logout session is redirected to the login screen, but now I want this page to be redirected to the home page. What I found in the encoding files:

in the main branch file:

<a href="{{path('log_out')}}"><i class="icon-key"></i> Log Out</a> 

in routing.yml

 #Route for logout page. log_out: pattern: /bid/logout 

Does anyone know how to change this redirect, please help me, I'm new to symfony Thanks

+9
source share
3 answers

Usually he is redirected to his homeland. Check the security.yml configuration file.

 firewalls: default: logout: path: /logout target: / #This is home url 
+16
source

The easiest way, in my humble opinion, is to simply do a redirect in your logoutAction (like that in your controller), for example:

 public function myLogoutAction() { // Your logout logic return $this->redirect($this->generateUrl('my_route')); } 
+1
source

In Symfony 4, the default logout action redirects to the / path. You can change the default behavior by setting the appropriate configuration parameter in the security.yml configuration file.

 security: ... firewalls: ... main: ... logout: ... target: app_login # you can specify a hard coded URL path or a route name 
0
source

Source: https://habr.com/ru/post/987980/


All Articles