forme création sortie

This commit is contained in:
marvin
2024-11-19 14:04:47 +01:00
parent 51fcbba8b2
commit 6403b41a3e
9 changed files with 344 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
<?php
namespace App\Controller;
use App\Entity\Sortie;
use App\Form\SortieType;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/sortie', name: 'sortie_')]
class SortieController extends AbstractController
{
#[Route('/creates', name: 'create', methods: ['GET', 'POST'])]
public function create(Request $request, EntityManagerInterface $entityManager): Response
{
$sortie = new Sortie();
// Créer le formulaire
$form = $this->createForm(SortieType::class, $sortie);
// Traiter la requête
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// Sauvegarder dans la base de données
$entityManager->persist($sortie);
$entityManager->flush();
// Rediriger après soumission
$this->addFlash('success', 'Sortie créée avec succès !');
return $this->redirectToRoute('sortie_create');
}
// Afficher le formulaire
return $this->render('sortie/create.html.twig', [
'form' => $form->createView(),
]);
}
}