[英]Route Error: Symfony 4 No route found for “GET /blog”
我遇到此错误:
Symfony \\ Component \\ HttpKernel \\ Exception \\ NotFoundHttpException:未找到“ GET / blog”的路由(来自“ http:// localhost:8000 / produits ”)
我在控制器的方法中添加了@Route注释(就像我在其他网站上看到的那样):
/**
* @Route("/blog", name="article.index")
* @return Response
* */
public function index():Response
{
return $this->render("blog/article.html.twig", [
"current_menu" => 'articles'
]);
}
我试图在@Route中添加methods = {“ GET”,“ HEAD”},但出现相同的错误
我该如何解决这个问题?
这对我有用(在路径末尾添加/ ):
/**
* @Route("/blog/", name="article.index")
* @return Response
* */
public function index():Response
{
return $this->render("blog/article.html.twig", [
"current_menu" => 'articles'
]);
}
您还至少需要use Symfony\\Component\\Routing\\Annotation\\Route;
在文件开头(在其他“使用”行中),还需要启用某些用于Route注释的框架设置。 另外,blog / article.html.twig如何指代路线或路径?
全新安装的Symfony 4实例将需要composer require doctrine / annotations软件包,除非其他软件包已经安装了该软件包。
https://symfony.com/doc/current/routing.html#creating-routes具有更多详细信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.