简体   繁体   English

Symfony2尽管路径存在但无法生成URL

[英]Symfony2 Unable to generate URL although path exist

The controller: 控制器:

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(){

    }
}

The view: 风景:

{% 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 %}

The error: An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "/login_check" as such route does not exist.") in UserBundle:Login:login.html.twig at line 3. 错误:在模板的渲染过程中在UserBundle:Login:login.html.twig中的模板渲染过程中引发了异常(“无法为命名路由“ / login_check”生成URL,因为该路由不存在。“) 3。

I've tried calling the login_check path itself and it is working, i've also replaced the path for the form to "login", it is also not working. 我尝试调用login_check路径本身,并且该路径正在工作,我还替换了该表单的路径以“登录”,但该路径也不起作用。

I've also tried clearing the cache and everything but its not working also. 我也曾尝试清除缓存和所有内容,但它也无法正常工作。

Anyone have a solution for this? 有人对此有解决方案吗?

Route from terminal: 从航站楼出发的路线:

 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  

In order to use <form action="{{ path('/login_check') }}" method="post"> 为了使用<form action="{{ path('/login_check') }}" method="post">

Your route should be: 您的路线应为:

/**
 * @Route("/login_check", name="/login_check")
 */

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Symfony2:LiipImagineBundle-异常:无法为命名路由“ _imagine_image_upload_thumbnail”生成URL,因为该路由不存在 - Symfony2: LiipImagineBundle - Exception: Unable to generate a URL for the named route “_imagine_image_upload_thumbnail” as such route does not exist Symfony2 / Twig:生成用于CDN的备用绝对URL路径? - Symfony2 / Twig : Generate Alternate Absolute URL Path for use with CDN? Symfony2注释无法为命名路由生成URL - Symfony2 annotation Unable to generate a URL for the named route 在 Symfony2 中生成具有特定方案的绝对 URL - Generate absolute URL with specific scheme in Symfony2 Symfony2无法找到路径的控制器 - Symfony2 Unable to find the controller for path Symfony2显式获取URL的路径信息 - Symfony2 get path info of URL explicitely Symfony - 为命名路由生成 URL 但不存在 - Symfony - Generate URL for named route but does not exist Symfony2,路由自动重定向并自动生成新路径,这可能吗? - Symfony2, routing autoredirect and also auto generate new path, is it possible? 如何使用symfony2中的url不在请求变量中生成页面链接 - How to generate a link to a page with a request variable not in the url in symfony2 如何在Symfony2中使用JavaScript生成其他页面的URL? - How to generate URL for other pages using JavaScript in Symfony2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM