控制器:
namespace Main\UserBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\SecurityContextInterface;
class LoginController extends Controller
{
/**
* @Route("login")
*/
public function indexAction(Request $request){
return $this->render('UserBundle:Login:login.html.twig');
}
/**
* @Route("login_check")
*/
public function loginCheckAction(){
return true;
}
/**
* @Route("logout")
*/
public function logoutAction(){
}
}
观点:
{% extends '::base.html.twig' %}
{% block body %}
<form action="{{ path('/login_check') }}" method="post">
<label for="username">Email:</label>
<input type="text" id="email" name="email" value="{{ last_username }}" />
<label for="password">Password:</label>
<input type="password" id="password" name="_password" />
<button type="submit">login</button>
</form>
{% endblock body %}
错误: 在呈现模板期间抛出异常(&#34;无法生成指定路由的URL&#34; / login_check&#34;因为此类路由不存在。&#34;)在UserBundle中:登录:第3行的login.html.twig。
我尝试过调用login_check路径并且它正在运行,我也将表单的路径替换为&#34; login&#34;,它也无效。
我还尝试清除缓存以及除此之外的所有内容。
任何人都有解决方案吗?
从终端路由:
main_user_login_index ANY ANY ANY /login
main_user_login_logincheck ANY ANY ANY /login_check
main_user_login_logout ANY ANY ANY /logout
main_user_register_index ANY ANY ANY /register
main_admin_login_index ANY ANY ANY /admin/login/{name}
main_admin_login_logincheck ANY ANY ANY /admin/login_check
main_admin_login_logout ANY ANY ANY /admin/logout
答案 0 :(得分:1)
使用<form action="{{ path('/login_check') }}" method="post">
您的路线应该是:
/**
* @Route("/login_check", name="/login_check")
*/