简体   繁体   中英

Symfony 2 Unable to find the controller for path /login_check

I'm deploying a Symfony2 based application in a production server but I'm unable to login. I get an error saying that the controller parameter for the route /login_check is missing. This should be handled by the firewall configuration which is incluided in the security.yml file and the security.yml file is included in the app/config/config.yml file. The application deploys fine in my development machine and I can login (with the prod configuration) but I get a 500 Error in the server when I try to access /login_check route. Any hint will be greatly useful and welcome. Thanks in advance.

I get the following error in my prod.log:

[2014-06-26 00:52:56] security.DEBUG: Write SecurityContext in the session [] []
[2014-06-26 00:53:12] request.INFO: Matched route "login_check" (parameters: "_route": "login_check") [] []
[2014-06-26 00:53:12] security.INFO: Populated SecurityContext with an anonymous Token [] []
[2014-06-26 00:53:12] security.INFO: No expression found; abstaining from voting. [] []
[2014-06-26 00:53:12] request.WARNING: Unable to look for the controller as the    "_controller" parameter is missing [] []
[2014-06-26 00:53:12] request.ERROR: Uncaught PHP Exception   Symfony\Component\HttpKernel\Exception\NotFoundHttpException: "Unable to find the controller   for path "/login_check". Maybe you forgot to add the matching route in your routing   configuration?" at /homepages/36/d516172930/htdocs/covivedev/app/bootstrap.php.cache line   995 [] []
[2014-06-26 00:53:12] security.DEBUG: Write SecurityContext in the session [] []

Here is my app/config/config.yml

    imports:
            - { resource: parameters.yml }
            - { resource: security.yml }

    framework:
        secret:          %secret%
        router:
            resource: "%kernel.root_dir%/config/routing.yml"
            strict_requirements: %kernel.debug%
        form:            ~
        csrf_protection: ~
        validation:      { enable_annotations: true }
        templating:
            engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_proxies: ~
    session:         ~
    fragments:       ~

# Twig Configuration
twig:
    debug:            %kernel.debug%
    strict_variables: %kernel.debug%

# Assetic Configuration
assetic:
    debug:          %kernel.debug%
    use_controller: false
    bundles:        [ ]
    filters:
        cssrewrite: ~

# Doctrine Configuration
doctrine:
    dbal:
        driver:   %database_driver%
        host:     %database_host%
        port:     %database_port%
        dbname:   %database_name%
        user:     %database_user%
        password: %database_password%
        charset:  UTF8

    orm:
        auto_generate_proxy_classes: %kernel.debug%
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: smtp
    host:      ssl://smtp.gmail.com
    username:  max21campos@gmail.com
    password:  xxxxx
    spool:     { type: memory }

my app/config/security.yml looks like the following:

jms_security_extra:
    secure_all_services: false
    expressions: true

security:
    encoders:
        PromoMails\CoviveBundle\Entity\Usuario:
            algorithm:        sha1
            encode_as_base64: false
            iterations:       1

    providers:
         covive_provider:
            entity: 
                class: PromoMailsCoviveBundle:Usuario
                property: username

    firewalls:
        covive:
            pattern:  /
            anonymous: ~
            provider: covive_provider
            security: true
           form_login: 
              login_path:  /
              check_path:  /login_check
              always_use_default_target_path: true
              default_target_path: /home
              use_referer: true
            logout:
                path: /logout
                target: /
            remember_me:
                key: SaveUser
                lifetime: 0
                path: /.*
                domain: ~


    access_control:
        - { path: ^/login_check, roles: IS_AUTHENTICATED_ANONYMOUSLY}
        - { path: ^/vendedor, roles: ROLE_VENDEDOR }

My app/config/routing.yml only includes the BundleRouting:

promo_mails_covive:
    resource: "@PromoMailsCoviveBundle/Resources/config/routing.yml"
    prefix:   /

My bundle routing has the following:

promo_mails_covive_homepage:
    pattern: /
    defaults: 
        _controller: PromoMailsCoviveBundle:Default:index

home:
    pattern: /home
    defaults: 
        _controller: PromoMailsCoviveBundle:Default:home

login_check:
    pattern: /login_check

logout:
    pattern: /logout

Following the error:

[2014-06-26 00:53:12] request.ERROR: Uncaught PHP Exception Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException: "Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration?"[...]

In your routing.yml maybe you must add the _controller:

login_check: pattern: /login_check defaults: { _controller: YourBundle:ControllerName:login_check }

In addition, here's you can find the Symfony 2 documentation about routing .

Something you can check is to modify the order of firewall statements in your security.yml

  1. Above, your login_check statement
  2. At the bottom of firewalls, your default firewall (here it is called covive)

If a reader can confirm, that'd be great. The error message says to add a _controller line, but that's not the real problem; it's only a suggestion, and the login_check URLs do not need _controller statements;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM