Redirect after login in Symfony 2

别来无恙 提交于 2020-01-11 20:56:34

问题


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: ~

回答1:


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

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!)



来源:https://stackoverflow.com/questions/8374753/redirect-after-login-in-symfony-2

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