Symfony2.1: Unable to find the controller for path "/login_check"

falsch picture falsch · Sep 13, 2012 · Viewed 27.2k times · Source

I used the "Using a traditional login form" tutorial from symfony.com to authentificate my users. With a simple http auth it works great.

After the login was submitted I get this Exception:

Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration?

Well, in the tutorial I read:

You will not need to implement a controller for the /login_check URL as the firewall will automatically catch and process any form submitted to this URL.

I defined the routes and set the firewall settings:

security.yml

firewalls:
    dev:
        pattern:  ^/(_(profiler|wdt)|css|images|js)/
        security: false
    backend:
        pattern:    ^/backend
        anonymous: ~
        form_login:
            provider: entity
            login_path: /login
            check_path: /login_check
            #use_forward: true
        logout:
            path:   /logout
            target: /

routing.yml

login:
    pattern:   /login
    defaults:  { _controller: VitaSecurityBundle:Default:login }
login_check:
    pattern:   /login_check
logout:
    pattern:   /logout

Answer

Żabojad picture Żabojad · Jan 8, 2013

The problem you are having is described here:

See http://symfony.com/doc/current/book/security.html, section "Avoid Common Pitfalls"

  1. Be sure /login_check is behind a firewall Next, make sure that your check_path URL (e.g. /login_check) is behind the firewall you're using for your form login (in this example, the single firewall matches all URLs, including /login_check). If /login_check doesn't match any firewall, you'll receive a Unable to find the controller for path "/login_check" exception.

In this example, your pattern specifies a prefix of /backend for secured paths. To work, your login check should be behind this same firewall.

So, to match the pattern which you have specified in your firewall, put login_check on a url path like this: /backend/login_check