src/Controller/HomeController.php line 74

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. $categories = $em->getRepository(Category::class)
  22. ->createQueryBuilder('c')
  23. ->setMaxResults(3)
  24. ->getQuery()
  25. ->getResult();
  26. $products = $em->getRepository(Product::class)
  27. ->createQueryBuilder('p')
  28. ->where('p.category NOT IN (:categories)')
  29. ->setParameter('categories', $categories)
  30. ->setMaxResults(3)
  31. ->getQuery()
  32. ->getResult();
  33. return $this->render('home/index.html.twig', [
  34. 'categories' => $categories,
  35. 'products' => $products,
  36. ]);
  37. }
  38. /**
  39. * @Route("/home/about", name="about")
  40. */
  41. public function about()
  42. {
  43. return $this->render('home/about.html.twig');
  44. }
  45. /**
  46. * @Route("/home/cgv", name="cgv")
  47. */
  48. public function cgv()
  49. {
  50. return $this->render('home/cgv.html.twig');
  51. }
  52. /**
  53. * @Route("/home/cg", name="cg")
  54. */
  55. public function cg()
  56. {
  57. return $this->render('home/cg.html.twig');
  58. }
  59. /**
  60. * @Route("/home/ml", name="ml")
  61. */
  62. public function ml()
  63. {
  64. return $this->render('home/ml.html.twig');
  65. }
  66. /**
  67. * @Route("/home/confidentialite", name="confidentialite")
  68. */
  69. public function confidentialite()
  70. {
  71. return $this->render('home/confidentialite.html.twig');
  72. }
  73. }