Bonjour, je n'arrive pas à comprendre pourquoi Symfony n'accepte pas mes paramètres ici :
Code twig : Sélectionner tout - Visualiser dans une fenêtre à part {{ render(controller('App\\Controller\\AdminReportingController::new', {'manuscriptId': manuscript_id, 'chapterId': chapter_id} )) }}
Il s'agit d'un formulaire dans une modal à qui je passe des paramètres dans le new pour revenir sur la même page, je n'ai pas utilisé de jQuery, car je ne sais pas bien m'en servir... Lorsque je dump manuscript_id et chapter_id ils sont bien là...
J'ai cette erreur :Controller "App\Controller\AdminReportingController::new()" requires that you provide a value for the "$manuscriptId" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one.
ManuscriptController.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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 <?php namespace App\Controller; use App\Entity\Reporting; use App\Form\ReportingType; use App\Repository\ChapterRepository; use App\Repository\ReportingRepository; use App\Repository\ManuscriptRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; class ManuscriptController extends AbstractController { // comment fait symfony pr récupérer le GET ? #[Route('/manuscript/{id}', name: 'manuscript')] public function index(int $id, ManuscriptRepository $manuscriptRepository, ChapterRepository $chapterRepository): Response { $manuscript = $manuscriptRepository->findOneBy(['id' => $id]); $genres = $manuscript->getGenres()->getValues(); $genres = implode(" ", $genres); // récupérer tous les chapitres qui on le manuscript_id $chapters = $chapterRepository->findBy(['manuscriptId' => $id]); return $this->render('manuscript/index.html.twig', [ 'chapters' => $chapters, 'manuscript' => $manuscript, 'genres' => $genres, ]); } #[Route('/manuscript/{manuscriptId}/chapter/{chapterId}', name: 'manuscript_chapter', methods: ['GET', 'POST'])] public function showChapter(int $manuscriptId, int $chapterId, ManuscriptRepository $manuscriptRepository, ChapterRepository $chapterRepository, ReportingRepository $reportingRepository, Request $request, EntityManagerInterface $entityManager): Response { $reportings = $reportingRepository->findAll(); $manuscript = $manuscriptRepository->findOneBy(['id' => $manuscriptId]); $chapter = $chapterRepository->findOneBy(['id' => $chapterId]); $chapters = $chapterRepository->findBy(['manuscriptId' => $manuscriptId]); $currentChapterIndex = array_search($chapter, $chapters); for($i = 0; $i < count($chapters); $i++ ) { if(isset($chapters[$currentChapterIndex + 1])) { $nextChapter = $chapters[$currentChapterIndex + 1]; } else { $nextChapter = null; }; } // $referer = $request->headers->get('referer'); // return new RedirectResponse($referer); return $this->render('manuscript/manuscript_chapter.html.twig', [ 'chapter' => $chapter, 'chapters' => $chapters, 'manuscript' => $manuscript, 'next_chapter' => $nextChapter, 'reportings' => $reportings, 'chapter_id' => $chapterId, 'manuscript_id' => $manuscriptId ]); } }
adminReportingController.php
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95 <?php namespace App\Controller; use App\Entity\Reporting; use App\Form\ReportingType; use App\Repository\ReportingRepository; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; #[Route('/admin/reporting')] class AdminReportingController extends AbstractController { #[Route('/', name: 'admin_reporting_index', methods: ['GET', 'POST'])] public function index(ReportingRepository $reportingRepository): Response { return $this->render('admin_reporting/index.html.twig', [ 'reportings' => $reportingRepository->findAll(), ]); } #[Route('/new', name: 'admin_reporting_new', methods: ['GET', 'POST'])] public function new(int $manuscriptId, int $chapterId, Request $request, EntityManagerInterface $entityManager): Response { $reporting = new Reporting(); $form = $this->createForm(ReportingType::class, $reporting); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->persist($reporting); $entityManager->flush(); return $this->redirectToRoute('manuscript_chapter', [ 'manuscriptId' => $manuscriptId, 'chapterId' => $chapterId, ], Response::HTTP_SEE_OTHER); } return $this->renderForm('admin_reporting/new.html.twig', [ 'reporting' => $reporting, 'form' => $form, 'manuscriptId' => $manuscriptId, 'chapterId' => $chapterId, ]); } #[Route('/{id}', name: 'admin_reporting_show', methods: ['GET'])] public function show(Reporting $reporting): Response { return $this->render('admin_reporting/show.html.twig', [ 'reporting' => $reporting, ]); } #[Route('/{id}/edit', name: 'admin_reporting_edit', methods: ['GET', 'POST'])] public function edit(Request $request, Reporting $reporting, EntityManagerInterface $entityManager): Response { $form = $this->createForm(ReportingType::class, $reporting); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $entityManager->flush(); return $this->redirectToRoute('admin_reporting_index', [], Response::HTTP_SEE_OTHER); } dd($form()->get("data")); return $this->renderForm('admin_reporting/edit.html.twig', [ 'reporting' => $reporting, 'form' => $form, ]); } #[Route('/{id}', name: 'admin_reporting_delete', methods: ['POST'])] public function delete(Request $request, Reporting $reporting, EntityManagerInterface $entityManager): Response { if ($this->isCsrfTokenValid('delete'.$reporting->getId(), $request->request->get('_token'))) { $entityManager->remove($reporting); $entityManager->flush(); } return $this->redirectToRoute('admin_reporting_index', [], Response::HTTP_SEE_OTHER); } }
manuscript_chapter.html.twig
Code twig : Sélectionner tout - Visualiser dans une fenêtre à part
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 {% extends 'base.html.twig' %} {% block title %}Hello ManuscriptController! {% endblock %} {% block body %} <section class="global mb-5" id="content"> <div class="container padding-top"> <div class="panels"> <div class="panel-body mt-3 position-relative"> {% if chapters|length > 0 %} {% if chapter|length > 0 %} <h2 class="text-center">{{ chapter.title }}</h2> <button class="btn dropdown-toggle jQuery2 position-absolute top-0 start-0" type="button" id="dropdownMenuButton1" data-bs-toggle="dropdown" aria-expanded="false"> Sélectionner un chapitre </button> <ul class="dropdown-menu dropdown-style-chapter" aria-labelledby="dropdownMenuButton1"> <div class="d-flex-column width-dropdown overflow-auto height-dropdown widthDropDown"> {% for chapter in chapters %} <li> <a href="{{ path('manuscript_chapter', {'chapterId': chapter.id, 'manuscriptId': manuscript.id}) }}" class=" btn w-100 border-dropdown">{{ chapter.title }}</a> </li> {% endfor %} </div> </ul> <article class="text-left text-lg-justify mt-5 container"> <p> {{ chapter.content }}</p> <div class=" d-flex justify-content-end mt-5"> {% if next_chapter is not null %} <a href="{{ path('manuscript_chapter', {'chapterId': next_chapter.id, 'manuscriptId': manuscript.id}) }}" class=" btn w-25 justify-content-end border-dropdown">Chapitre suivant</a> {% else %} <p>FIN</p> {% endif %} </div> </article> {% endif %} {% endif %} <!-- Button trigger modal --> <button id="modalButton"type="button" data-bs-toggle="modal" class="btn btn-primary" data-bs-target="#exampleModal"> Signaler </button> <!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Signaler un contenu</h5> <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> </div> <div class="modal-body"> {{ render(controller('App\\Controller\\AdminReportingController::new', {'manuscriptId': manuscript_id, 'chapterId': chapter_id} )) }} </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Fermer</button> <button type="button" class="btn btn-primary">Envoyer</button> </div> </div> </div> </div> </div> </div> </div> </section> {% endblock %}
Partager