<?php
namespace App\Controller;
use App\Repository\EvenementRepository;
use Doctrine\ORM\NonUniqueResultException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
class EventController extends AbstractController
{
private $repository;
public function __construct(EvenementRepository $repository)
{
$this->repository = $repository;
}
/**
* @Route("/evenements", name="events")
*/
public function index(): Response
{
$events = $this->repository->findAll();
return $this->render('event/index.html.twig', [
'banner' => 'events.webp',
'events' => $events,
'titre' => 'Nos évènements à venir',
'sousTitre' => 'se rencontrer',
]);
}
/**
* @Route("/evenement/{slug}", name="event")
* @throws NonUniqueResultException
*/
public function show($slug)
{
$event = $this->repository->findOneBySlug($slug);
if (!$event){
return $this->redirectToRoute('events');
}
return $this->render('event/show.html.twig', [
'banner' => 'events.jpg',
'event' => $event,
'titre' => $event->getNom(),
'sousTitre' => 'évènement',
]);
}
}