Php Symfony2无法生成URL,尽管路径存在
控制员:Php Symfony2无法生成URL,尽管路径存在,php,symfony,Php,Symfony,控制员: 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\H
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 %}
为了使用
你的路线应该是:
/**
* @Route("/login_check", name="/login_check")
*/
您好,结果是一样的,无法生成URL。您好@KarlWong,您是否使用“php应用程序/控制台路由:调试”cmd来验证可用的路由?请使用此cmd显示您的可用路线及其名称。谢谢,我为其添加了一个名称。我认为路径就是链接。控制器中的操作名称是否符合规则,与路由表中的名称有关?
/**
* @Route("/login_check", name="/login_check")
*/