gpt4 book ai didi

Symfony4 "object not found by the @ParamConverter annotation"404 错误

转载 作者:行者123 更新时间:2023-12-02 19:45:10 29 4
gpt4 key购买 nike

我发现 Symfony4 具有类似的博客示例,如 https://symfony.com/doc/current/routing.html 中描述的然后我添加了一条新路线来添加/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 错误:
App\Entity\Description @ParamConverter 注释找不到对象

最佳答案

经过几个小时寻找解决方案,我终于读到了 https://symfony.com/doc/current/routing.html并了解 /blog/{id} 注释 catch /blog/about 路由但无法使用它!

通过在我的 Controller 文件中切换函数顺序:

/**
* @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,
]);
}

效果很好!

@tom 提到的解决方案是唯一具有多个实体和 Controller 的解决方案!

关于Symfony4 "object not found by the @ParamConverter annotation"404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51521607/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com