-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormationControllerV2Controller.php
80 lines (67 loc) · 3.01 KB
/
FormationControllerV2Controller.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace App\Controller;
use App\Entity\Formation;
use App\Form\FormationType;
use App\Repository\FormationRepository;
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('/formation/controller/v2')]
final class FormationControllerV2Controller extends AbstractController
{
#[Route(name: 'app_formation_controller_v2_index', methods: ['GET'])]
public function index(FormationRepository $formationRepository): Response
{
return $this->render('formation_controller_v2/index.html.twig', [
'formations' => $formationRepository->findAll(),
]);
}
#[Route('/new', name: 'app_formation_controller_v2_new', methods: ['GET', 'POST'])]
public function new (Request $request, EntityManagerInterface $entityManager): Response
{
$formation = new Formation();
$form = $this->createForm(FormationType::class, $formation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->persist($formation);
$entityManager->flush();
return $this->redirectToRoute('app_formation_controller_v2_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('formation_controller_v2/new.html.twig', [
'formation' => $formation,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_formation_controller_v2_show', methods: ['GET'])]
public function show(Formation $formation): Response
{
return $this->render('formation_controller_v2/show.html.twig', [
'formation' => $formation,
]);
}
#[Route('/{id}/edit', name: 'app_formation_controller_v2_edit', methods: ['GET', 'POST'])]
public function edit(Request $request, Formation $formation, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(FormationType::class, $formation);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('app_formation_controller_v2_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('formation_controller_v2/edit.html.twig', [
'formation' => $formation,
'form' => $form,
]);
}
#[Route('/{id}', name: 'app_formation_controller_v2_delete', methods: ['POST'])]
public function delete(Request $request, Formation $formation, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete' . $formation->getId(), $request->getPayload()->getString('_token'))) {
$entityManager->remove($formation);
$entityManager->flush();
}
return $this->redirectToRoute('app_formation_controller_v2_index', [], Response::HTTP_SEE_OTHER);
}
}