Search code examples
symfony4

Symfony4 "object not found by the @ParamConverter annotation" 404 error


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",
    ]);
}

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


Solution

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

    eg.

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

    The requirement is a regex.