src/Controller/FrontendEventController.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use App\Entity\Event;
  7. class FrontendEventController extends AbstractController {
  8.     /**
  9.      * @Route("/events", name="events")
  10.      */
  11.     public function index(EntityManagerInterface $em) {
  12.         $events $em->getRepository(Event::class)->findBy([], ['startDate' => 'DESC']);
  13.         return $this->render('frontend/event/index.html.twig', [
  14.                     'events' => $events
  15.         ]);
  16.     }
  17.     /**
  18.      * @Route("/event/{slug}", name="event")
  19.      */
  20.     public function single(EntityManagerInterface $em$slug) {
  21.         $event $em->getRepository(Event::class)->findOneBy(['slug' => $slug]);
  22.         if (null === $event) {
  23.             return $this->redirectToRoute('events');
  24.         }
  25.         return $this->render('frontend/event/single.html.twig', [
  26.                     'event' => $event
  27.         ]);
  28.     }
  29. }