symfony - 带前缀的 FOSUserBundle 注销不起作用

标签 symfony localization fosuserbundle

我在使用 symfony2 和 FOSUserBundle 时遇到了一个非常奇怪的问题。

我可以使用/en/logout 注销,但不能使用/nl/logout 或/fr/logout。

当我尝试使用 nl 或 fr 注销时,我得到:

You must activate the logout in your security firewall configuration.

虽然我配置了它。我似乎无法理解为什么/en/logout 有效而其余部分无效。

这是我的代码:

安全.yml

security:
providers:
    fos_userbundle:
        id: fos_user.user_provider.username_email

encoders:
    FOS\UserBundle\Model\UserInterface: sha512

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
            check_path: fos_user_security_check
            default_target_path: /%locale%/login
            always_use_default_target_path: true
            failure_path:   /%locale%/login
        logout:
            path: /%locale%/logout
            target: homepage
        anonymous:    true

路由.yml

user bundle > FOS
    fos_user_security:
        resource: "@FOSUserBundle/Resources/config/routing/security.xml"
        prefix: /{_locale}
        requirements:
            _locale: fr|nl|en

Controller

    class LoginController extends Controller {

    /**
     * @Route("{_locale}/logout-test", name="logout", defaults={"_locale"="en"} , requirements = {"_locale" = "fr|en|nl"})
     * @Template()
     */
    public function logoutAction()
    {
        $test = "";
        #throw new \RuntimeException('You must activate the logout in your security firewall configuration.');
        #return $this->redirect($this->generateUrl('homepage'));;
    }
}

任何人都可以帮助我,或者告诉我下一步该去哪里吗?我们将不胜感激

最佳答案

在配置文件中,您需要使用路由而不是 URL。如果它以“/”开头,它将被视为 URL,否则它将被视为路由。如果您使用路由而不是 URL,则会自动处理区域设置。例如,这是我的 security.yml 配置:

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

关于symfony - 带前缀的 FOSUserBundle 注销不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14941989/

相关文章:

javascript - 如何动态更改 DrawerNavigator 的导航选项(标题)?

php - Symfony 2.5 中的 FOSBundle View 不会被自定义 View 覆盖

Symfony 2.8 FOSUserBundle 在注销时删除 cookie

php - 使用 Sonata 和 MongoDB 更新 Symfony 中的许多引用时出现问题

php - 交响乐 3 : What should I checkin to git?

localization - Google 会惩罚跨多个国家域的内容复制吗?

php - Symfony2 : Getting the list of user roles in FormBuilder

php - 如何在 Symfony 5 的其他目录中自动注册 'controllers as services'

Symfony Apache 2 : Unable to create the cache directory/var/cache

java 网页本地化支持