Compare commits
2 Commits
82640eef86
...
8213037f96
Author | SHA1 | Date | |
---|---|---|---|
8213037f96 | |||
9dfd212718 |
46
src/Controller/CuisinierController.php
Normal file
46
src/Controller/CuisinierController.php
Normal file
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class CuisinierController extends AbstractController
|
||||
{
|
||||
#[Route('/cuisinier/ajouter', name: 'ajouter_cuisinier')]
|
||||
public function ajouter(Request $request, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$cuisinier = new Cuisinier();
|
||||
$form = $this->createForm(CuisinierType::class, $cuisinier);
|
||||
|
||||
$form->handleRequest($request);
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$entityManager->persist($cuisinier);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Cuisinier ajouté avec succès !');
|
||||
return $this->redirectToRoute('ajouter_cuisinier');
|
||||
}
|
||||
|
||||
return $this->render('cuisinier/ajouter.html.twig', [
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
#[Route('/cuisinier/supprimer/{id}', name: 'supprimer_cuisinier', methods: ['POST'])]
|
||||
public function supprimer(int $id, EntityManagerInterface $entityManager): Response
|
||||
{
|
||||
$cuisinier = $entityManager->getRepository(Cuisinier::class)->find($id);
|
||||
|
||||
if (!$cuisinier) {
|
||||
throw $this->createNotFoundException('Ce cuisinier n\'existe pas');
|
||||
}
|
||||
|
||||
$entityManager->remove($cuisinier);
|
||||
$entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Cuisinier supprimé avec succès !');
|
||||
return $this->redirectToRoute('ajouter_cuisinier');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user