src/Controller/HomeController.php line 53

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\EvenementRepository;
  4. use App\Repository\RealisationRepository;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  9. use Symfony\Contracts\Cache\ItemInterface;
  10. class HomeController extends AbstractController
  11. {
  12.     private $realisationRepository;
  13.     private $evenementRepository;
  14.     public function __construct(RealisationRepository $realisationRepositoryEvenementRepository $evenementRepository)
  15.     {
  16.         $this->realisationRepository $realisationRepository;
  17.         $this->evenementRepository $evenementRepository;
  18.     }
  19.     /**
  20.      * @Route("/", name="home")
  21.      */
  22.     public function index(): Response
  23.     {
  24.         $cache = new FilesystemAdapter();
  25.         $lastsReal $cache->get('home-lastsReal', function (ItemInterface $item) {
  26.             $item->expiresAfter(6);
  27.             return $this->realisationRepository->findLasts(4);
  28.         });
  29.         $lastsEvent $cache->get('home-lastsEvent', function (ItemInterface $item) {
  30.             $item->expiresAfter(6);
  31.             return $this->evenementRepository->findLasts(5);
  32.             //return $this->evenementRepository->eventAfter();
  33.         });
  34.     
  35.         
  36.         return $this->render('home/index.html.twig', [
  37.             'lastsReal' => $lastsReal,
  38.             'lastsEvent' => $lastsEvent,
  39.         ]);
  40.     }
  41. }