我有最奇怪的问题。一切都很好,突然间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中添加的。
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()
{
/* ... */
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句