Symfony4“@ParamConverter 注释未找到对象"404错误 [英] Symfony4 "object not found by the @ParamConverter annotation" 404 error

查看:46
本文介绍了Symfony4“@ParamConverter 注释未找到对象"404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现 Symfony4 具有类似的博客示例,例如 https://symfony.com/doc/当前/routing.html然后我添加了一个新的路由来添加/blog/about 页面.所以我的 src/Controller/BlogController.php 中的一部分代码是:

I discover Symfony4 with similar blog sample like describe in https://symfony.com/doc/current/routing.html Then I added a new route to add /blog/about page. So a part of code in my src/Controller/BlogController.php is:

/**
 * @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 注释未找到对象

and when I run locahost:8000/blog/about, it returns me a 404 error :
App\Entity\Description object not found by the @ParamConverter annotation

推荐答案

如果向路由添加需求,那么顺序无关紧要.

If you add a requirement to the route, then the order doesn't matter.

例如

/**
 * @Route("/blog/{id}", name="blog_show", requirements={"id":"\d+"})
 */

要求是一个正则表达式.

The requirement is a regex.

这篇关于Symfony4“@ParamConverter 注释未找到对象"404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆