src/Controller/MainController.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Header;
  4. use App\Repository\AboutRepository;
  5. use App\Repository\HeaderRepository;
  6. use App\Repository\NewsRepository;
  7. use App\Repository\TitlesRepository;
  8. use Doctrine\ORM\EntityManagerInterface;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class MainController extends AbstractController
  13. {
  14.     private $entityManager;
  15.     public function __construct(EntityManagerInterface $entityManager)
  16.     {
  17.         $this->entityManager = $entityManager;
  18.     }
  19.     /**
  20.      * @Route("/{_locale<%app.supported_locales%>}/", name="app_main")
  21.      */
  22.     public function index(HeaderRepository $headerRepository, AboutRepository $aboutRepository, TitlesRepository $titlesRepository, NewsRepository $newsRepository): Response
  23.     {
  24.         $header = $headerRepository->findByIsActive(1);
  25.         $new = $newsRepository->findByIsActive(1);
  26.         $inter1 = $titlesRepository->findTitleByTag('intervention_1');
  27.         $inter2 = $titlesRepository->findTitleByTag('intervention_2');
  28.         $inter3 = $titlesRepository->findTitleByTag('intervention_3');
  29.         $inter4 = $titlesRepository->findTitleByTag('intervention_4');
  30.         $success = $titlesRepository->findTitleByTag('success_index');
  31.         $about = $aboutRepository->findAboutByTag('about_home');
  32.         return $this->render('main/index.html.twig', [
  33.             'headers' => $header,
  34.             'aboutHome' => $about,
  35.             'success' => $success,
  36.             'inter1' => $inter1,
  37.             'inter2' => $inter2,
  38.             'inter3' => $inter3,
  39.             'inter4' => $inter4,
  40.             'news' => $new
  41.         ]);
  42.     }
  43.     /**
  44.      * @Route("/")
  45.      */
  46.     public function indexNoLocale(): Response {
  47.         return $this->redirectToRoute('app_main', ['_locale'=>'fr']);
  48.     }
  49. }