@scotty_walker
To create a logout function in Symfony, you can follow these steps:
1 2 |
logout: path: /logout |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
namespace AppController; use SymfonyComponentHttpFoundationResponse; use SymfonyComponentRoutingAnnotationRoute; use SymfonyComponentSecurityHttpLogoutLogoutSuccessHandlerInterface; class SecurityController extends AbstractController { /** * @Route("/logout", name="app_logout") */ public function logout(LogoutSuccessHandlerInterface $logoutSuccessHandler): Response { return $logoutSuccessHandler->onLogoutSuccess(); } } |
1 2 3 4 5 |
security: # ... logout: path: app_logout target: app_homepage # optional - redirect target after logout |
1
|
<a href="{{ logout_path('app_logout') }}">Logout</a> |
This should create a functional logout function in Symfony. When the user clicks on the logout link, Symfony will invalidate their session and redirect them to the configured logout target.