Bonjour,
Voici l'erreur qui survient après une tentative de modifier un objet : Expected argument of type "WUX\ReportingBundle\Entity\Checklists", "NULL" given
Au moment du if ($form->handleRequest($request)->isValid()) j'ai cette erreur
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 public function selectedAction($id, Request $request){ ... $em = $this->getDoctrine()->getManager(); $list_repo = $em->getRepository('WUXReportingBundle:Checklists')->find($id); /* OK je peux accéder au contenu de l'objet */ $content = $em->getRepository('WUXReportingBundle:ChecklistCont')->find($request->request->keys()[0]); $content->setChecklist($list_repo); /* Je met l'objet Checklists dans mon ChecklistCont */ $form = $this->get('form.factory')->createNamed($request->request->keys()[0], ChecklistContType::class, $content); if ($form->handleRequest($request)->isValid()) { $em->persist($content); $em->flush(); $request->getSession()->getFlashBag()->add('notice', 'Critère bien sauvegardé'); } ... }
Voici les 2 entités :
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 /** * Checklists * * @ORM\Table(name="checklists") * @ORM\Entity(repositoryClass="WUX\ReportingBundle\Repository\ChecklistsRepository") * @UniqueEntity(fields="nom", message="Ce nom existe déjà") */ class Checklists { /** * @var ArrayCollection $criteres * @ORM\OneToMany(targetEntity="WUX\ReportingBundle\Entity\ChecklistCont", mappedBy="checklist", cascade={"persist"}) */ private $criteres; /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="nom", type="string", length=255, unique=true) */ private $nom; /** * Get id * * @return int */ public function getId() { return $this->id; } public function __construct() { $this->date = new \Datetime(); $this->datemodif = new \Datetime(); $this->criteres = new ArrayCollection(); } /** * Add critere * * @param \WUX\ReportingBundle\Entity\ChecklistCont $critere * * @return Checklists */ public function addCritere(\WUX\ReportingBundle\Entity\ChecklistCont $critere) { $this->criteres[] = $critere; return $this; } /** * Remove critere * * @param \WUX\ReportingBundle\Entity\ChecklistCont $critere */ public function removeCritere(\WUX\ReportingBundle\Entity\ChecklistCont $critere) { $this->criteres->removeElement($critere); } /** * Get criteres * * @return \Doctrine\Common\Collections\Collection */ public function getCriteres() { return $this->criteres; } }Le formulaire
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235 /** * ChecklistCont * * @ORM\Table(name="checklist_cont") * @ORM\Entity(repositoryClass="WUX\ReportingBundle\Repository\ChecklistContRepository") */ class ChecklistCont { /** * Un critère ne peut être contenu que dans une seule liste * @ORM\ManyToOne(targetEntity="WUX\ReportingBundle\Entity\Checklists", inversedBy="criteres") * @ORM\JoinColumn(nullable=false) */ private $checklist; /** * @ORM\ManyToMany(targetEntity="WUX\ReportingBundle\Entity\Role", cascade={"persist"}, inversedBy="criteres") */ private $roles; /** * @ORM\ManyToMany(targetEntity="WUX\ReportingBundle\Entity\Etape", cascade={"persist"}) */ private $etapes; /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="numero", type="string", length=255, unique=false) */ private $numero; /** * Get id * * @return int */ public function getId() { return $this->id; } /** * Set numero * * @param string $numero * * @return ChecklistCont */ public function setNumero($numero) { $this->numero = $numero; return $this; } /** * Get numero * * @return string */ public function getNumero() { return $this->numero; } /** * Constructor */ public function __construct() { $this->etataudit = new ArrayCollection(); $this->roles = new ArrayCollection(); } /** * Add etataudit * * @param \WUX\ReportingBundle\Entity\EtatAudit $etataudit * * @return ChecklistCont */ public function addEtataudit(EtatAudit $etataudit) { $this->etataudit[] = $etataudit; return $this; } /** * Remove etataudit * * @param \WUX\ReportingBundle\Entity\EtatAudit $etataudit */ public function removeEtataudit(EtatAudit $etataudit) { $this->etataudit->removeElement($etataudit); } /** * Get etataudit * * @return \Doctrine\Common\Collections\Collection */ public function getEtataudit() { return $this->etataudit; } /** * Add role * * @param \WUX\ReportingBundle\Entity\Role $role * * @return ChecklistCont */ public function addRole(Role $role) { $this->roles[] = $role; return $this; } /** * Remove role * * @param \WUX\ReportingBundle\Entity\Role $role */ public function removeRole(Role $role) { $this->roles->removeElement($role); } /** * Get roles * * @return \Doctrine\Common\Collections\Collection */ public function getRoles() { return $this->roles; } /** * Add checklist * * @param \WUX\ReportingBundle\Entity\Checklists $checklist * * @return ChecklistCont */ public function addChecklist(Checklists $checklist) { $this->checklists[] = $checklist; return $this; } /** * Remove checklist * * @param \WUX\ReportingBundle\Entity\Checklists $checklist */ public function removeChecklist(Checklists $checklist) { $this->checklists->removeElement($checklist); } /** * Add etape * * @param \WUX\ReportingBundle\Entity\Etape $etape * * @return ChecklistCont */ public function addEtape(\WUX\ReportingBundle\Entity\Etape $etape) { $this->etapes[] = $etape; return $this; } /** * Remove etape * * @param \WUX\ReportingBundle\Entity\Etape $etape */ public function removeEtape(\WUX\ReportingBundle\Entity\Etape $etape) { $this->etapes->removeElement($etape); } /** * Get etapes * * @return \Doctrine\Common\Collections\Collection */ public function getEtapes() { return $this->etapes; } /** * Set checklist * * @param \WUX\ReportingBundle\Entity\Checklists $checklist * * @return ChecklistCont */ public function setChecklist(\WUX\ReportingBundle\Entity\Checklists $checklist) { $this->checklist = $checklist; return $this; } /** * Get checklist * * @return \WUX\ReportingBundle\Entity\Checklists */ public function getChecklist() { return $this->checklist; } }
Je ne comprend pas trop d'ou vient l'erreur car je set bien mon objet de type Checklists et il est complet. J'ai du louper un truc mais je ne vois pas trop quoi.
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 public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('numero', TextType::class, array( 'attr' => array('class' => 'input'), )) ->add('roles', EntityType::class, array( 'class' => 'WUX\ReportingBundle\Entity\Role', 'choice_label' => 'name', 'multiple' => true, 'expanded' => true,)) ->add('etapes', EntityType::class, array('class' => 'WUX\ReportingBundle\Entity\Etape', 'choice_label' => 'name', 'multiple' => true, 'expanded' => true,)) ->add('checklist', EntityType::class, array( 'class' => 'WUX\ReportingBundle\Entity\Checklists', 'choice_label' => 'nom', )) ->add('Add', SubmitType::class, array( 'attr' => array('class' => 'btn-1'), )) ; }
Merci
Partager