我遇到了这个相当常见的 Symfony 登录失败并出现此错误消息的问题:
Unable to find the controller for path "/auth/login_check".
这个问题的常见答案是login_check
路由不在防火墙后面,但在我的情况下它是!这是我的配置文件:
应用程序/配置/security.yml
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
auth_area:
pattern: ^/auth/(login|login_check)
anonymous: ~
secured_area:
pattern: ^/
form_login:
login_path: /auth/login
check_path: /auth/login_check
logout:
path: /auth/logout
target: /
应用程序/配置/路由.yml
login:
pattern: /auth/login
defaults: { _controller: AuthBundle:Default:login }
login_check:
pattern: /auth/login_check
logout:
pattern: /auth/logout
AuthBundle/Controller/DefaultController.php
public function loginAction()
{
$form = $this->createForm(new UserType(), new User());
return $this->render('AuthBundle:Default:login.html.twig', array(
'form' => $form->createView(),
'action' => $this->generateUrl('login_check'),
));
}
AuthBundle/Form/Type/UserType.php
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('username', 'text', array('label' => 'Login:'));
$builder->add('password', 'password', array('label' => 'Password:'));
}
AuthBundle/Resources/views/Default/login.html.twig
...
<form action="{{ action }}" method="POST">
{{ form_widget(form) }}
<input type="submit" value="Login" />
</form>
...
我的表单是使用路由login_check
作为目标(/auth/login_check
URL)创建的。
secured_area
防火墙应该匹配所有 URL,所以/auth/login_check
应该在其中。然而,我不断收到这个错误。我究竟做错了什么?