<?php
namespace App\Controller;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
use App\Entity\Event;
class FrontendEventController extends AbstractController {
/**
* @Route("/events", name="events")
*/
public function index(EntityManagerInterface $em) {
$events = $em->getRepository(Event::class)->findBy([], ['startDate' => 'DESC']);
return $this->render('frontend/event/index.html.twig', [
'events' => $events
]);
}
/**
* @Route("/event/{slug}", name="event")
*/
public function single(EntityManagerInterface $em, $slug) {
$event = $em->getRepository(Event::class)->findOneBy(['slug' => $slug]);
if (null === $event) {
return $this->redirectToRoute('events');
}
return $this->render('frontend/event/single.html.twig', [
'event' => $event
]);
}
}