Symfony2: Create a logout link Symfony2: Create a logout link symfony symfony

Symfony2: Create a logout link


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.