I am managing users in my symfony2 project. I am able to login and logout without problems. Now, I would like to create a logout link (instead of typing app_dev.php/logout).
I have tryed
<a href="/logout">Logout</a>
But this link is deleting the app_dev.php and i have only /logout which does not exist.
here is my security.yml
security:
encoders:
MDPI\BackendBundle\Entity\Users:
id: mdpi.backend.backendencoder.class
providers:
secured_area:
entity: { class: MDPI\BackendBundle\Entity\Users, property: email }
firewalls:
secured_area:
pattern: ^/
anonymous: ~
form_login:
login_path: /login
check_path: /login_check
logout:
path: /logout
target: /
access_control:
- { path: ^/(?!login)(.*), role: ROLE_admins }
- { path: /login.*, role: IS_AUTHENTICATED_ANONYMOUSLY }
Thank you very much.
I created the link this way: (I use TWIG)
<a href="{{ path('user_logout') }}">Logout</a>
And in my "UserBundle", in the routing.yml file added
user_logout:
pattern: /logout
When you are using the FOSUserBundle you can use
{{ path('fos_user_security_logout') }}
Since Symfony 2.7 you can use Twig logout_path
or logout_url
functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With