Symfony slug в URL
Есть 2 варианта: Первый через MapEntity:#[Route('/article/{slug}', name: 'blog_article', methods: ['GET'])] public function article( #[MapEntity(mapping: ['slug' => 'slug'])] Article $article ): Response { return $this->render('blog/article/show.html.twig', [ 'article' => $article, ]); }
Второй вариант через doctrine.yaml:doctrine: orm: controller_resolver: auto_mapping: true
тогда:#[Route('/article/{slug}', name: 'blog_article_show', methods: ['GET'])] public function article( Article $article ): Response { return $this->render('blog/article/show.html.twig', [ 'article' => $article, ]); }
1 месяц назад