src/Controller/ProductController.php line 15

Open in your IDE?
  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. /**
  10. * @Route("/produit/{slug}", name="app_product")
  11. */
  12. public function index($slug, ProductRepository $productRepository): Response
  13. {
  14. $product = $productRepository->findOneBySlug($slug);
  15. if (!$product) {
  16. return $this->redirectToRoute('app_home');
  17. }
  18. return $this->render('product/index.html.twig', [
  19. 'product' => $product,
  20. ]);
  21. }
  22. }