2025-10-13 17:26:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Controller;
|
|
|
|
|
|
|
|
|
|
use App\Entity\Membre;
|
|
|
|
|
use App\Form\MembreType;
|
2025-10-16 17:09:34 +02:00
|
|
|
use App\Repository\MembreRepository;
|
2025-10-13 17:26:15 +02:00
|
|
|
use Doctrine\ORM\EntityManagerInterface;
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
use Symfony\Component\Routing\Attribute\Route;
|
|
|
|
|
|
|
|
|
|
#[Route('/membre')]
|
|
|
|
|
final class MembreController extends AbstractController
|
|
|
|
|
{
|
|
|
|
|
#[Route(name: 'app_membre_index', methods: ['GET'])]
|
2025-10-16 17:09:34 +02:00
|
|
|
public function index(MembreRepository $membreRepository): Response
|
2025-10-13 17:26:15 +02:00
|
|
|
{
|
2025-10-16 17:09:34 +02:00
|
|
|
$membres = $membreRepository->findAll();
|
2025-10-13 17:26:15 +02:00
|
|
|
|
|
|
|
|
return $this->render('membre/index.html.twig', [
|
|
|
|
|
'membres' => $membres,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/new', name: 'app_membre_new', methods: ['GET', 'POST'])]
|
|
|
|
|
public function new(Request $request, EntityManagerInterface $entityManager): Response
|
|
|
|
|
{
|
|
|
|
|
$membre = new Membre();
|
|
|
|
|
$form = $this->createForm(MembreType::class, $membre);
|
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
|
$entityManager->persist($membre);
|
|
|
|
|
$entityManager->flush();
|
|
|
|
|
|
|
|
|
|
return $this->redirectToRoute('app_membre_index', [], Response::HTTP_SEE_OTHER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->render('membre/new.html.twig', [
|
|
|
|
|
'membre' => $membre,
|
|
|
|
|
'form' => $form,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/{id}', name: 'app_membre_show', methods: ['GET'])]
|
|
|
|
|
public function show(Membre $membre): Response
|
|
|
|
|
{
|
|
|
|
|
return $this->render('membre/show.html.twig', [
|
|
|
|
|
'membre' => $membre,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/{id}/edit', name: 'app_membre_edit', methods: ['GET', 'POST'])]
|
|
|
|
|
public function edit(Request $request, Membre $membre, EntityManagerInterface $entityManager): Response
|
|
|
|
|
{
|
|
|
|
|
$form = $this->createForm(MembreType::class, $membre);
|
|
|
|
|
$form->handleRequest($request);
|
|
|
|
|
|
|
|
|
|
if ($form->isSubmitted() && $form->isValid()) {
|
|
|
|
|
$entityManager->flush();
|
|
|
|
|
|
|
|
|
|
return $this->redirectToRoute('app_membre_index', [], Response::HTTP_SEE_OTHER);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->render('membre/edit.html.twig', [
|
|
|
|
|
'membre' => $membre,
|
|
|
|
|
'form' => $form,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Route('/{id}', name: 'app_membre_delete', methods: ['POST'])]
|
|
|
|
|
public function delete(Request $request, Membre $membre, EntityManagerInterface $entityManager): Response
|
|
|
|
|
{
|
2025-10-16 17:09:34 +02:00
|
|
|
// ⚠ Correction : use $request->request->get('_token') instead of $request->getPayload()
|
|
|
|
|
if ($this->isCsrfTokenValid('delete'.$membre->getId(), $request->request->get('_token'))) {
|
2025-10-13 17:26:15 +02:00
|
|
|
$entityManager->remove($membre);
|
|
|
|
|
$entityManager->flush();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->redirectToRoute('app_membre_index', [], Response::HTTP_SEE_OTHER);
|
|
|
|
|
}
|
|
|
|
|
}
|