作者:黄河豚 | 来源:互联网 | 2022-12-09 16:16
我发现了类似https://symfony.com/doc/current/routing.html中所述的类似博客示例的Symfony4。
然后,我添加了一条新路由来添加/ blog / about页面。因此,我的src / Controller / BlogController.php中的一部分代码是:
/**
* @Route("/blog/{id}", name="blog_show")
*/
public function show(Description $article) {
return $this->render('blog/show.html.twig', [
'article' => $article,
]);
}
/**
* @Route("blog/about", name="about")
*/
public function about() {
return $this->render('blog/about.html.twig', [
'copyright' => "GLPI 3",
]);
}
当我运行locahost:8000 / blog / about时,它返回404错误:@ParamConverter批注未找到
App \ Entity \ Description 对象
1> bcag2..:
After hours to find solution, I finally read https://symfony.com/doc/current/routing.html and understand that the /blog/{id} annotation catch /blog/about route but can't use it!
By switching functions order in my controller file:
/**
* @Route("/blog/about", name="blog_about")
*/
public function about() {
return $this->render('blog/about.html.twig', [
'copyright' => "GLPI 3",
]);
}
/**
* @Route("/blog/{id}", name="blog_show")
*/
public function show(Description $article) {
return $this->render('blog/show.html.twig', [
'article' => $article,
]);
}
It works fine !
The solution as mentionned by @tom is the only one with severals entities and controllers !