简体   繁体   English

Symfony:注销后如何重定向到主页

[英]Symfony: How to redirect to home page after logout

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. 我已经在symfony上提供了一个预构建项目,其中注销会话重定向到登录屏幕,但现在我希望该页面在主页上重定向。 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 在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 有谁知道如何改变这个重定向请嘻嘻我,我是symfony的新手谢谢

Normally it is redirect to home. 通常它会重定向到家。 Check your security.yml config file. 检查security.yml配置文件。

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

The easiest way, to my humble opinion, is to simply do a redirection in your logoutAction (so in your controller), like this : 根据我的拙见,最简单的方法是在你的logoutAction中进行重定向(所以在你的控制器中),如下所示:

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

On Symfony 4, by default, the logout action redirects to the / path. 在Symfony 4上,默认情况下,注销操作会重定向到/ path。 You can change the default behavior by setting the proper configuration parameter in the security.yml config file. 您可以通过在security.yml配置文件中设置正确的配置参数来更改默认行为。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM