简体   繁体   中英

Symfony2 logout controller not found

I have managed to get the login working in Symfony2, but I have trouble with /logout. I get an exception saying it can't find the controller for the route. However, I was under the impression that Symfony deals with the logout process, just like it deals with the login?

(part of) my security.yml file:

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: /

My (relevant) routes:

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

_login_check:
    pattern: /login_check/

_logout:
    pattern: /logout/

--edit: logout button code:

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

I eventually fixed it with this security.yml section:

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

thanks to everyone for trying to help out on this :)

fixed it with this security.yml section:

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

Try this may be helpful to you..:)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM