FOSUserBundle logout with prefix doesn't work

人走茶凉 提交于 2019-11-30 20:05:55

In your configuration file, you need to use routes instead of URLs. If it starts with a "/" it will be treated as an URL, else it will be treated as a route. If you use routes instead of URLs, the locale will be taken care of automatically. For example, here is my security.yml configuration:

security:
  public:
    pattern:   ^/
    form_login:
      login_path: fos_user_security_login
      check_path: fos_user_security_check
      provider: fos_userbundle
      csrf_provider: form.csrf_provider
      default_target_path: index
    anonymous: true
    logout:
      path: fos_user_security_logout
      target: index

I leave this for future reference, in addition to @jfcartier's answer:

In case you need a custom logout path instead of fos_user_security_logout:

# app/config/security.yml
...
  logout:
     path: my_logout
     target: homepage

... then you also need to define it in routing.yml:

# app/config/routing.yml
app:
    resource: "@AppBundle/Controller/"
    type:     annotation

my_logout:
    path: /logout

fos_user:
    resource: "@FOSUserBundle/Resources/config/routing/all.xml"

Though, make sure that it's defined before fos_user - otherwise you'll get the same error: You must activate the logout in your security firewall configuration.

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