[英]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.