Symfony: How to redirect to home page after logout

让人想犯罪 __ 提交于 2020-12-04 18:31:02

问题


I have provided a pre build project on symfony in which the logout session redirects to the login screen, but now i want that page to redirect on the home page instead. What i have found in the coding files is this:

in the base twig 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

Do anyone know how to change this redirection please hep me out, i am a total newbie to symfony Thanks


回答1:


Normally it is redirect to home. Check your security.yml config file.

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



回答2:


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

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



回答3:


The easiest way, to my humble opinion, is to simply do a redirection in your logoutAction (so in your controller), like this :

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


来源:https://stackoverflow.com/questions/30476384/symfony-how-to-redirect-to-home-page-after-logout

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!