Symfony2 身份验证“login_check"找不到路径 [英] Symfony2 Authentication "login_check" path not found
问题描述
我是 Symfony2 的新手,我正在尝试创建一个基本的注册 + 登录系统.因此,在 Symfony2 文档的帮助下,我创建了这个 security.yml:
I'm new to Symfony2 and I'm trying to create a basic registration + login system. So, with the help of the Symfony2 documentation I created this security.yml:
security:
encoders:
TestCompany\InternetBundle\Entity\Member:
algorithm: sha1
encode_as_base64: false
iterations: 1
role_hierarchy:
ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ ROLE_USER, ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH ]
providers:
administrators:
entity: { class: TestCompanyInternetBundle:Member, property: username }
firewalls:
admin_area:
pattern: ^/admin
anonymous: ~
form_login:
login_path: /login
check_path: /login_check
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
我使用了这个路由:
login_check:
pattern: /login_check
login:
pattern: /login
defaults: { _controller: TestCompanyInternetBundle:Admin:login }
根据 http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form 我不需要为 login_check 路由实现控制器.然而,Symfony 将这个错误返回给我:
According to http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form I do NOT need to implement a controller for the login_check route. Yet, Symfony returns this error to me:
Unable to find the controller for path "/login_check". Maybe you forgot to add the matching route in your routing configuration?
你有没有发现我在这里做错了什么?登录页面几乎是文档中使用的页面的精确副本.错误发生在页面上:http://localhost/SymfonyTest/web/app_dev.php/login_check
,这是我在使用登录表单后被发送到的页面.
Do you see anything I could have done wrong here? The login page is almost an exact copy of the one used in the documentation. The error occurs on the page: http://localhost/SymfonyTest/web/app_dev.php/login_check
, which is the page I get sent to after using the login form.
推荐答案
http://symfony.com/doc/current/book/security.html#using-a-traditional-login-form
确保 /login_check
位于防火墙后面.
Be sure /login_check
is behind a firewall.
因此,在您的示例中,您为安全区域指定了前缀/admin,因此您的登录检查路由也应具有该前缀,例如/admin/login_check
接下来,确保您的 check_path URL(例如/login_check)位于您用于表单登录的防火墙之后(在本例中,单个防火墙匹配所有 URL,包括/login_check).如果/login_check 与任何防火墙都不匹配,您将收到无法找到路径/login_check"的控制器异常.
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.
示例 security.yml
配置:
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
secured_area:
pattern: ^/
form_login:
login_path: /login
check_path: /login_check
logout:
path: /demo/secured/logout
target: /demo/
anonymous: ~
....
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
这篇关于Symfony2 身份验证“login_check"找不到路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!