src/Controller/DefaultController.php line 23

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Entity\Poll;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. class DefaultController extends AbstractController
  10. {
  11.     private EntityManagerInterface $entityManager;
  12.     public function __construct(EntityManagerInterface $entityManager)
  13.     {
  14.         $this->entityManager $entityManager;
  15.     }
  16.     #[Route(path'/'name'index'methods: ['GET'])]
  17.     public function index(): Response
  18.     {
  19.         $polls $this->entityManager->getRepository(Poll::class)->findAll();
  20.         return $this->render('index.html.twig', [
  21.             'polls' => $polls,
  22.         ]);
  23.     }
  24. }