找不到Symfony2注销控制器

时间:2012-08-23 09:38:41

标签: php symfony logout

我已经设法让登录工作在Symfony2中,但是我遇到了/ logout问题。我得到一个例外,说它无法找到该路线的控制器。但是,我的印象是Symfony处理注销过程,就像它处理登录一样?

(我的security.yml文件的一部分):

firewalls:
    login_firewall:
        pattern:    ^/login/
        anonymous:  ~
    secured_area:
        pattern:    ^/(dashboard|directories|login_check)/
        anonymous: ~
        form_login:
            login_path:  /login/
            check_path:  /login_check/
        logout:
            path:   /logout/
            target: /

我的(相关)路线:

_login:
    pattern: /login/
    defaults: { _controller: NanoBundle:Login:index } 

_login_check:
    pattern: /login_check/

_logout:
    pattern: /logout/

- 编辑:退出按钮代码:

<a href="{{path('_logout')}}">Logout</a>

2 个答案:

答案 0 :(得分:0)

我最终用这个security.yml部分修复了它:

    secured_area:
        pattern:    .*
        security: true
        form_login:
            login_path:  /login/
            check_path:  /login_check/
        logout:
            path: /logout/
            invalidate_session: true

感谢所有人试图帮助解决这个问题:)

答案 1 :(得分:0)

使用此security.yml部分修复它:

security:
    providers:
        fos_userbundle:
            id: fos_user.user_manager

encoders:
    FOS\UserBundle\Model\UserInterface: sha512

firewalls:
    main:
        pattern: ^/
        form_login:
            provider: fos_userbundle
            csrf_provider: form.csrf_provider
        logout:       true
        anonymous:    true

access_control:
    - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/admin/*, role: ROLE_ADMIN }
     # URL of FOSUserBundle which need to be available to anonymous users
    - { path: ^/_wdt, role: IS_AUTHENTICATED_ANONYMOUSLY }
    - { path: ^/_profiler, role: IS_AUTHENTICATED_ANONYMOUSLY }

role_hierarchy:
    ROLE_ADMIN:       ROLE_USER
    ROLE_SUPER_ADMIN: ROLE_ADMIN

试试这可能对你有帮助.. :))