HegreEtConfort/src/Controller/InterventionController.php
2024-11-21 16:31:49 +01:00

51 lines
1.5 KiB
PHP

<?php
namespace App\Controller;
use App\Entity\Intervention;
use App\Form\InterventionType;
use App\Repository\InterventionRepository;
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;
class InterventionController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly InterventionRepository $interventionRepository
)
{
}
#[\Symfony\Component\Routing\Annotation\Route('/intervention/add', name: 'fault_add')]
public function add(Request $request): Response
{
$fault = new Intervention();
$form = $this->createForm(InterventionType::class, $fault);
$form->handleRequest($request);
if($form->isSubmitted() && $form->isValid())
{
$this->entityManager->persist($fault);
$this->entityManager->flush();
return $this->redirectToRoute("app_fault_list");
}
return $this->render('fault/add.html.twig', [
'form' => $form,
]);
}
#[Route('/fault/list', name: 'fault_list')]
public function list(): Response
{
$fault = $this->faultRepository->findAll();
return $this->render('fault/list.html.twig', [
'fault' => $fault,
]);
}
}