Symfony找不到路线

时间:2013-11-05 16:32:27

标签: php symfony routing

我有一个最奇怪的问题。一切都很好,突然间symfony显示

"No route found for "GET /"

所以我检查了路由器..我的控制器中的任何一条路线都在那里。

所以我添加了路由到 routing.yml ,现在它抛出

An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "_edit_user" as such route does not exist.") in C:\xampp\htdocs\zadanie\src\Cart\Bundle/Resources/views/User/index.html.twig at line 2

即使名称为“_edit_user”的操作位于从路由调用的操作之下。

到底发生了什么事?

编辑: 这是 router:debug 所说的:

_wdt                     ANY    ANY    ANY  /_wdt/{token}
_profiler_home           ANY    ANY    ANY  /_profiler/
_profiler_search         ANY    ANY    ANY  /_profiler/search
_profiler_search_bar     ANY    ANY    ANY  /_profiler/search_bar
_profiler_purge          ANY    ANY    ANY  /_profiler/purge
_profiler_info           ANY    ANY    ANY  /_profiler/info/{about}
_profiler_import         ANY    ANY    ANY  /_profiler/import
_profiler_export         ANY    ANY    ANY  /_profiler/export/{token}.txt
_profiler_phpinfo        ANY    ANY    ANY  /_profiler/phpinfo
_profiler_search_results ANY    ANY    ANY  /_profiler/{token}/search/results
_profiler                ANY    ANY    ANY  /_profiler/{token}
_profiler_router         ANY    ANY    ANY  /_profiler/{token}/router
_profiler_exception      ANY    ANY    ANY  /_profiler/{token}/exception
_profiler_exception_css  ANY    ANY    ANY  /_profiler/{token}/exception.css
_configurator_home       ANY    ANY    ANY  /_configurator/
_configurator_step       ANY    ANY    ANY  /_configurator/step/{index}
_configurator_final      ANY    ANY    ANY  /_configurator/final
blog_show                ANY    ANY    ANY  /

和blog_show是我在routing.yml中添加的..

1 个答案:

答案 0 :(得分:3)

Symfony2不会将操作方法​​自动映射到路由名称。如果您需要一个可路由的操作方法,则必须明确指定。

我个人喜欢使用注释进行路由,所以如果你想这样做,那么首先将其添加到 app / config / routing.yml

YourBundle:
    resource: "@YourBundle/Controller/"
    type:     annotation
    prefix:   /

然后将路由信息添加到控制器。以默认控制器为例:

<强>的src /你/捆绑/控制器/ DefaultController.php

<?php

namespace Your\Bundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;

class DefaultController extends Controller
{
  /**
   * @Route("desired/edit_user/uri", name="_edit_user")
   */
  public function _edit_userAction()
  {
    /* ... */
  }
}
相关问题