src/Controller/ProductController.php line 13

  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\ProductRepository;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class ProductController extends AbstractController
  8. {
  9.     #[Route('/produit/{slug}'name'app_product')]
  10.     public function index($slugProductRepository $productRepository): Response
  11.     {
  12.         $product $productRepository->findOneBySlug($slug);
  13.         if (!$product) {
  14.             return $this->redirectToRoute('app_home');
  15.         }
  16.         return $this->render('product/index.html.twig', [
  17.             'product' => $product,
  18.         ]);
  19.     }
  20. }