In a Symfony 2.7.7 project, I implemented a traditional login form as described in the official documentation. Unfortunately, I get the following error every time the user logout:
Unable to find the controller for path "/logout". The route is wrongly configured.
I followed this configuration http://symfony.com/doc/2.7/book/security.html#logging-out and I did it successfully many times in the past but I can't find the error.
Here you are my code:
#security.yml
security:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login:
pattern: ^/login$
anonymous: ~
main:
anonymous: ~
form_login:
login_path: /login
check_path: /login_check
secured_area:
pattern: ^/
form_login: ~
remember_me:
key: "%secret%"
lifetime: 604800
path: /
domain: ~
logout:
path: /logout
target: /login
access_control:
- { path: ^/admin/utenti/modifica-password-scaduta, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/admin, roles: ROLE_ADMIN }
- { path: ^/aziende, roles: [ROLE_ADMIN, ROLE_ADMINISTRATIVE_PERSONNEL, ROLE_DOCTOR] }
- { path: ^/pazienti, roles: [ROLE_ADMIN, ROLE_ADMINISTRATIVE_PERSONNEL, ROLE_DOCTOR] }
- { path: ^/cartelle-sanitarie, roles: [ROLE_ADMIN, ROLE_ADMINISTRATIVE_PERSONNEL, ROLE_DOCTOR] }
#routing.yml
app:
resource: "@AppBundle/Controller/"
type: annotation
logout:
path: /logout
The logout path is included in the list provided by router:debug
Name Method Scheme Host Path
login_route ANY ANY ANY /login
login_check ANY ANY ANY /login_check
logout ANY ANY ANY /logout
I'm aware that many discussions are focused on this problem (i.e. http://www.forosdelweb.com/f68/symfony-2-7-logout-fallo-1133307/ or http://ambracode.com/index/show/99164) but I can't find the error from many days and I'm stuck!
Thank you
UPDATE: I have temporary fixed it defining a logout action in the SecurityController:
/**
* @Route("/logout", name="logout")
*/
public function logoutAction()
{
$this->container->get('security.context')->setToken(null);
return $this->redirect($this->generateUrl('login_route'));
}
Maybe this code can help someone who is in my same conditions!