src/Controller/HomeController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Category;
  4. use App\Entity\Product;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  8. class HomeController extends AbstractController
  9. {
  10.     private $session;
  11.     public function __construct(SessionInterface $session)
  12.     {
  13.         $this->session $session;
  14.     }
  15.     /**
  16.      * @Route("/", name="home")
  17.      */
  18.     public function index()
  19.     {        
  20.         $em $this->getDoctrine()->getManager();
  21.     
  22.         $categories $em->getRepository(Category::class)
  23.             ->createQueryBuilder('c')
  24.             ->setMaxResults(3)
  25.             ->getQuery()
  26.             ->getResult();
  27.     
  28.         $products $em->getRepository(Product::class)
  29.             ->createQueryBuilder('p')
  30.             ->where('p.category NOT IN (:categories)')
  31.             ->setParameter('categories'$categories)
  32.             ->setMaxResults(3)
  33.             ->getQuery()
  34.             ->getResult();    
  35.         return $this->render('home/index.html.twig', [
  36.             'categories' => $categories,
  37.             'products' => $products,
  38.         ]);
  39.     }      
  40.     /**
  41.      * @Route("/home/about", name="about")
  42.      */
  43.     public function about()
  44.     {
  45.         return $this->render('home/about.html.twig');
  46.     }
  47.     
  48.     /**
  49.      * @Route("/home/cgv", name="cgv")
  50.      */
  51.     public function cgv()
  52.     {
  53.         return $this->render('home/cgv.html.twig');
  54.     }
  55.     
  56.     /**
  57.      * @Route("/home/cg", name="cg")
  58.      */
  59.     public function cg()
  60.     {
  61.         return $this->render('home/cg.html.twig');
  62.     }
  63.     
  64.     /**
  65.      * @Route("/home/ml", name="ml")
  66.      */
  67.     public function ml()
  68.     {
  69.         return $this->render('home/ml.html.twig');
  70.     }
  71.     
  72.     /**
  73.      * @Route("/home/confidentialite", name="confidentialite")
  74.      */
  75.     public function confidentialite()
  76.     {
  77.         return $this->render('home/confidentialite.html.twig');
  78.     }
  79. }