symfony2 : using referer after login with fosuserbundle

蓝咒 提交于 2019-12-04 03:44:28

Ok i found a solution. In the login form i added an hidden field "_target_path" and give it the value of the referer...it seems to work fine

{% if app.request.get('_route') != app.request.headers.get('referer') %}    
    <input type="hidden" name="_target_path" value="{{ app.request.headers.get('referer') }}" />    
{% endif %}

This works for me with symfony 3.2,
while the referer-header solution didn't.

security.yml

 firewalls:
    main:
        form_login:
            use_referer: true

login.html.twig

<input type="hidden" 
       name="_target_path" 
       value="{{ app.session.get("_security.main.target_path") }}">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!