gpt4 book ai didi

php - Symfony 4 - 仅在 Profiler 中通过 @ParamConverter 注释找不到对象

转载 作者:行者123 更新时间:2023-12-03 05:19:48 26 4
gpt4 key购买 nike

问题仅出现在调试工具栏中。

这是我怀疑导致问题的代码

/**
* @Route("/{category_slug}/{slug}", name="content_show")
* @ParamConverter("content", options={"mapping": {"slug": "slug"}})
* @ParamConverter("category", options={"mapping": {"category_slug": "slug"}})
* @Method("GET")
*/
public function show(Category $category, Content $content): Response
{
$contents = $category->getContents();
return $this->render('content/show.html.twig', array(
'category' => $category,
'list' => $contents,
'content' => $content,
));
}

这是唯一带有ParamConverter的部分,也是出错前唯一修改过的部分。

页面显示正常,一切都找到了,错误调试工具栏不再工作并显示消息:

An error occurred while loading the web debug toolbar. Open the web profiler.

里面:

App\Entity\Content object not found by the @ParamConverter annotation.

带有 NotFoundHttpException

我清除了缓存,没有任何变化。代码仍然有效,但没有工具栏很痛苦,我不知道是什么原因造成的..

我尝试使用其他注释,例如:

  /**
* @Route("/{category_slug}/{slug}", name="content_show")
* @ParamConverter("category", class="App\Entity\Category", options={"mapping": {"category_slug": "slug"}})
* @Method("GET")
*/

等等。唯一的区别是,如果我从 paramconverter 中删除内容,它仍然有效,但错误出现在类别上。

提前致谢。

编辑:PHP 7.1.9
Composer json:

"require": {
"php": "^7.1.3",
"ext-iconv": "*",
"sensio/framework-extra-bundle": "^5.1",
"symfony/apache-pack": "^1.0",
"symfony/console": "^4.0",
"symfony/expression-language": "^4.0",
"symfony/flex": "^1.0",
"symfony/form": "^4.0",
"symfony/framework-bundle": "^4.0",
"symfony/lts": "^4@dev",
"symfony/maker-bundle": "^1.0",
"symfony/orm-pack": "^1.0",
"symfony/security-bundle": "^4.0",
"symfony/security-csrf": "^4.0",
"symfony/twig-bundle": "^4.0",
"symfony/validator": "^4.0",
"symfony/yaml": "^4.0",
"vich/uploader-bundle": "^1.8"
},
"require-dev": {
"symfony/dotenv": "^4.0",
"symfony/profiler-pack": "^1.0",
"symfony/web-server-bundle": "^4.0"
},

最佳答案

我在网上看到了很多与你相关的错误,我也遇到了它,我正在使用 CRUD 并且我的 url 与之前的路由之一匹配。

我刚刚发现这个命令php bin/console router:match url通过告诉我它使用了什么路线以及它如何匹配来帮助我。我认为这非常有用,应该分享。

关于php - Symfony 4 - 仅在 Profiler 中通过 @ParamConverter 注释找不到对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48448477/

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