je cherche a cree une page vue pour les article lorsque je cree ma route .

 #[Route("/product/{slug}", name: "app_product")]

    public function show(Produit $produit, $slug)
    {
        $produit = $this->entityManager->getRepository(Produit::class)->findOneBy(['slug' => $slug]);

        return $this->render('product/show.html.twig', array(
            'product' => $produit
        ));
    }
 <div class="row produit-container">
  {% for produit in produits %}
   <div class="col-md-4">
       <div class="produit-item text-center" >
           <a href="{{ path('app_product',{'slug' : produit.name}) }}"><img src="/uploads/{{produit.illustration }}" alt="{{ produit.name }}" class="img-fluid"></a>
           <h6>{{ produit.name }}</h6>
           <span class="produit-subtitle">{{ produit.subtitle }}</span>
            <span class="produit-price"> {{((produit.price /100)|number_format(2)) }} €</span>
       </div>

   </div>
  {% endfor %}
 </div>

Ce que je veux

une route une vue sur mes produit

Ce que j'obtiens

An exception has been thrown during the rendering of a template ("Parameter "slug" for route "app_product" must match "[^/]++" ("GLOCK 48 R/MOS SHIELD" given) to generate a corresponding URL.").

1 réponse


Bonjour,
c’est parce que dans ton lien, tu passe le nom du produit, il faut lui passer le slug.