登录Symfony 2后重定向 [英] Redirect after login in Symfony 2

查看:108
本文介绍了登录Symfony 2后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Symfony 2中,您可以设置注销目标,以便注销后将您重定向到/main.但是,使用登录名,您将被重定向到/.有没有办法为(成功的)登录设置目标?

In Symfony 2 you can set up a target for the logout so that after logout you will be redirected to /main. However with the login you will be redirected to /. Is there a manner to setup a target for a (successful) login as well?

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false

    login:
        pattern:  ^/m/login$
        security: false

    secured_area:
        pattern:    ^/m
        form_login:
            check_path: /m/login_check
            login_path: /m/login
        logout:
            path:   /m/logout
            target: /main
        anonymous: ~

推荐答案

是.您可以使用target_path选项.使用上面的示例:

Yes. You can use the target_path option. Using your example above:

firewalls:
    secured_area:
        form_login:
            always_use_default_target_path: true
            default_target_path: /loggedinpage

通过上述操作,成功登录后,始终会将用户重定向到/loggedinpage.有关安全组件的所有选项的详细信息,请参见 Symfony文档(尽管略微隐藏了) !)

With the above the user will always be redirected to /loggedinpage upon a successful login. Details of all the options for the security component are available in the Symfony docs (albeit slightly hidden away!)

这篇关于登录Symfony 2后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆