php Symfony2.1:无法找到路径“/login_check”的控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12409998/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Symfony2.1: Unable to find the controller for path "/login_check"
提问by falsch
I used the "Using a traditional login form"tutorial from symfony.com to authentificate my users. With a simple http auth it works great.
我使用来自 symfony.com的“使用传统登录表单”教程来验证我的用户。使用简单的 http auth 效果很好。
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?
无法找到路径“/login_check”的控制器。也许您忘记在路由配置中添加匹配的路由?
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.
您不需要为 /login_check URL 实现控制器,因为防火墙将自动捕获并处理提交到此 URL 的任何表单。
I defined the routes and set the firewall settings:
我定义了路由并设置了防火墙设置:
security.yml
安全.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
路由.yml
login:
pattern: /login
defaults: { _controller: VitaSecurityBundle:Default:login }
login_check:
pattern: /login_check
logout:
pattern: /logout
采纳答案by falsch
I found the solution to my problem
我找到了解决我的问题的方法
I added the /backend prefix to my paths, removed the 'anonymous: ~' line and commented out the ACL for backend.
我在路径中添加了 /backend 前缀,删除了“anonymous: ~”行并注释掉了后端的 ACL。
security.yml
安全.yml
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
login_firewall:
pattern: ^/backend/login$
anonymous: ~
backend:
pattern: ^/backend
form_login:
provider: entity
login_path: /backend/login
check_path: /backend/login_check
#use_forward: true
logout:
path: /backend/logout
target: /
access_control:
#- { path: ^/backend, roles: ROLE_USER }
routing.yml
路由.yml
login:
pattern: /backend/login
defaults: { _controller: VitaSecurityBundle:Default:login }
login_check:
pattern: /backend/login_check
logout:
pattern: /backend/logout
回答by ?abojad
The problem you are having is described here:
您遇到的问题描述如下:
See http://symfony.com/doc/current/book/security.html, section "Avoid Common Pitfalls"
请参阅http://symfony.com/doc/current/book/security.html,“避免常见陷阱”部分
- Be sure
/login_checkis 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.
- 确保
/login_check位于防火墙之后 接下来,确保您的 check_path URL(例如 /login_check)位于您用于表单登录的防火墙之后(在本例中,单个防火墙匹配所有 URL,包括 /login_check)。如果 /login_check 与任何防火墙都不匹配,您将收到无法找到路径“/login_check”的控制器异常。
In this example, your pattern specifies a prefix of /backend for secured paths. To work, your login check should be behind this same firewall.
在此示例中,您的模式为安全路径指定了前缀 /backend。要工作,您的登录检查应位于同一防火墙后面。
So, to match the pattern which you have specified in your firewall, put login_check on a url path like this: /backend/login_check
因此,要匹配您在防火墙中指定的模式,请将 login_check 放在这样的 url 路径上:/backend/login_check
回答by GuidoOM
The problem also tends to happen when you have two firewall with the same pattern. For example:
当您有两个具有相同模式的防火墙时,也会出现此问题。例如:
....
backend:
pattern: ^/*
....
frontend:
pattern: ^/*
You must change one of the two as follows:
您必须按如下方式更改两者之一:
....
backend:
pattern: ^/(administrador|backend)/*
....
frontend:
pattern: ^/*
回答by Bgi
Here is a sample code I used in a real-life project:
这是我在实际项目中使用的示例代码:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured_area:
pattern: ^/cmd
anonymous: ~
form_login:
check_path: /cmd/login_check
login_path: /cmd/login
remember_me:
always_remember_me: true
key: "%secret%"
path: /cmd
domain: ~ # Defaults to the current domain from $_SERVER
logout:
path: /cmd/logout
target: /
admin:
pattern: ^/admin
http_basic:
realm: "Administration"
free_area:
pattern: ^/
anonymous: ~
In my case, only the /cmd/ part is secured, the /admin/ part is also secured, but with HTTP security.
就我而言,只有 /cmd/ 部分受到保护,/admin/ 部分也受到保护,但具有 HTTP 安全性。
Maybe you should try: security.yml
也许你应该试试:security.yml
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
backend:
pattern: ^/backend
anonymous: ~
form_login:
provider: entity
login_path: /backend/login
check_path: /backend/login_check
#use_forward: true
logout:
path: /backend/logout
target: /
and as of routing.yml:
从routing.yml开始:
login:
pattern: /backend/login
defaults: { _controller: VitaSecurityBundle:Default:login }
login_check:
pattern: /backend/login_check
logout:
pattern: /backend/logout
I think your problem might come from the fact security is not activated in your / part (the pattern of your secured area is ^/backend)
我认为您的问题可能来自您的 / 部分未激活安全性(您的安全区域的模式是 ^/backend)
回答by wascou
This was not workging for me and I try something else :
这对我不起作用,我尝试了其他方法:
firewalls:
dev:
pattern: ^/(_profiler|_wdt|css|js)
security: false
login:
pattern: ^/login$
security: false
secured_area:
pattern: /(admin/.*|login_check)
provider: in_memory
form_login:
check_path: /login_check
login_path: /login
default_target_path: /admin
always_use_default_target_path: true
logout:
path: /logout
target: /
access_control:
- { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
- { path: ^/, roles: ROLE_ADMIN }
With the following explanation, simpler than the explanation from zabojad. The important thing is to put the login_check route inside a firewall and to let the login outside. With a or pattern you can succeed.
有了下面的解释,比zabojad的解释简单。重要的是将 login_check 路由放在防火墙内,并让登录在外面。使用 or 模式,您可以成功。
Max
最大限度

