Symfony2注销问题2

时间:2014-01-14 12:34:42

标签: symfony

下面给出了mys security.yml ..

security:
    encoders:
        Acme\HelloBundle\Entity\User:
            algorithm:        sha1
            encode_as_base64: false
            iterations:       1

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: [ ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]

providers:
    administrators:
        entity: { class: AcmeHelloBundle:User, property: username }

firewalls:
     secured_area:
        pattern:    ^/ual_courses
        logout:
            path: /logout
            target: /ual
        http_basic: ~     

access_control:
    - { path: ^/ual_courses, roles: ROLE_USER }

当我尝试使用注销时 “xyz.com/symfonyproject/test/web/app_dev.php/logout”它没有注销并显示错误消息“找不到”GET / logout“的路由。问题在哪里?

的routing.yml

    acme_hello_test:
    path:  /ual
    defaults: { _controller: AcmeHelloBundle:Hello:index}
acme_hello_static:
    path: /privacy
    defaults:
        _controller: FrameworkBundle:Template:template
        template: 'AcmeHelloBundle:Static:privacy.html.twig'
acme_hello_redirect:
    path: /redirect
    defaults: {_controller: AcmeHelloBundle:Hello:change}

AcmeHelloBundle_ual_courses:
        resource: "@AcmeHelloBundle/Resources/config/routing/courses.yml"
        prefix:   /ual_courses

logout:
   path:   /logout

1 个答案:

答案 0 :(得分:0)

你在运行什么版本的Symfony?您需要定义自2.1以来的特定/注销路线

  

请注意,您不需要为/ logout URL实现控制器,因为防火墙会处理所有事情。但是,您需要创建一个路径,以便您可以使用它来生成URL

有关详细信息,请参阅this paragraph of symfony firewall documentation

修改

确保您的注销路线位于防火墙后面。请参阅食谱的avoid common pitfall

您的防火墙仅捕获以/ ual_courses开头的模式,因此不包括/ logout。试试:

firewalls:
    secured_area:
        pattern:    ^/*
    #http_basic: ~

请注意http_basic已注释掉。