Bonjour à tous,
J'ai un soucis au niveau de ma base de données, quand je sélectionne un élément dans ma liste déroulante et que j'envoi mon formulaire, toutes les données sont bonnes, sauf la donnée de la liste déroulante qui reste sur 0! Alors voici mon formulaire de capsule:
Et voici mon Controlleur si vous en avez besoin:
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 <?php namespace SymfonyCapsule\CapsuleBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class CapsuleType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('idMaison', 'entity', array( 'label' => 'Nom de la maison* : ', 'class' => 'SymfonyCapsuleCapsuleBundle:Maison', 'property' => 'IdMaison', 'expanded' => false, 'multiple' => true, )) ->add('coteCaps', 'integer', array( 'label' => 'Cote de la capsule* : ', )) ->add('coteAnneeCaps', 'text', array( 'label' => 'Année de la cote* : ', )) ->add('serieCaps', 'text', array( 'label' => 'Nom de série de la capsule* : ', )) ->add('couleurCaps', 'text', array( 'label' => 'Couleur de la capsule* : ', )) ->add('diamCaps', 'text', array( 'label' => 'Diamètre de la capsule* : ', )) ->add('encocheCaps', 'text', array( 'label' => 'Encoche de la capsule* : ', )) ->add('photoCaps', 'url', array( 'label' => 'Url de la photo* : ', )) ; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'SymfonyCapsule\CapsuleBundle\Entity\Capsule' )); } public function getName() { return 'symfonycapsule_capsulebundle_capsuletype'; } }
Ainsi que ma classe capsule, et maison :
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 <?php namespace SymfonyCapsule\CapsuleBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use SymfonyCapsule\CapsuleBundle\Entity\Adherent; use SymfonyCapsule\CapsuleBundle\Form\AdherentType; use SymfonyCapsule\CapsuleBundle\Entity\Capsule; use SymfonyCapsule\CapsuleBundle\Form\CapsuleType; use Symfony\Component\HttpFoundation\Response; class DefaultController extends Controller { public function indexAction() { return $this->render('SymfonyCapsuleCapsuleBundle:Default:index.html.twig'); } public function inscriptionAction() { $em = $this->getDoctrine()->getEntityManager(); $a = new Adherent(); $form = $this->createForm(new AdherentType(), $a); $request = $this->getRequest(); if ($request->isMethod('POST')) { $form->bindRequest($request); if ($form->isValid()) { $a = $form->getData(); $em->persist($a); $em->flush(); return $this->redirect($this->generateUrl("symfony_capsule_capsule_homepage")); } } return $this->render('SymfonyCapsuleCapsuleBundle:Default:inscription.html.twig', array( 'form' => $form->createView(), )); } public function voirAction() { $em = $this->getDoctrine()->getEntityManager(); $capsule = $em->getRepository("SymfonyCapsuleCapsuleBundle:Capsule")->findAll(); return $this->render('SymfonyCapsuleCapsuleBundle:Default:voir.html.twig', array( 'capsules' => $capsule, )); } public function detailAction(Capsule $capsule) { return $this->render('SymfonyCapsuleCapsuleBundle:Default:detail.html.twig', array( 'capsule' => $capsule, )); } public function ajouterAction() { $em = $this->getDoctrine()->getEntityManager(); $a = new Capsule(); $form = $this->createForm(new CapsuleType(), $a); $request = $this->getRequest(); if ($request->isMethod('POST')) { $form->bindRequest($request); if ($form->isValid()) { $a = $form->getData(); //$a->setIdMaison($) == ''; $em->persist($a); $em->flush(); return $this->redirect($this->generateUrl("symfony_capsule_capsule_index")); } } return $this->render('SymfonyCapsuleCapsuleBundle:Default:ajouter.html.twig', array( 'form' => $form->createView(), )); } }
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366 <?php namespace SymfonyCapsule\CapsuleBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Capsule * * @ORM\Table(name="capsule") * @ORM\Entity */ class Capsule { /** * @var integer * * @ORM\Column(name="id_caps", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $idCaps; /** * @var integer * * @ORM\Column(name="id_maison", type="integer", nullable=false) */ private $idMaison; /** * @var integer * * @ORM\Column(name="cote_caps", type="integer", nullable=false) */ private $coteCaps; /** * @var integer * * @ORM\Column(name="cote_annee_caps", type="integer", nullable=false) */ private $coteAnneeCaps; /** * @var string * * @ORM\Column(name="serie_caps", type="string", length=32, nullable=false) */ private $serieCaps; /** * @var string * * @ORM\Column(name="couleur_caps", type="string", length=32, nullable=false) */ private $couleurCaps; /** * @var string * * @ORM\Column(name="diam_caps", type="string", length=15, nullable=false) */ private $diamCaps; /** * @var string * * @ORM\Column(name="encoche_caps", type="string", length=3, nullable=true) */ private $encocheCaps; /** * @var string * * @ORM\Column(name="estampee_caps", type="string", length=3, nullable=true) */ private $estampeeCaps; /** * @var string * * @ORM\Column(name="insert_caps", type="string", length=3, nullable=true) */ private $insertCaps; /** * @var string * * @ORM\Column(name="languette_caps", type="string", length=3, nullable=true) */ private $languetteCaps; /** * @var string * * @ORM\Column(name="photo_caps", type="string", length=255, nullable=false) * */ private $photoCaps; /** * Get idCaps * * @return integer */ public function getIdCaps() { return $this->idCaps; } /** * Set idMaison * * @param integer $idMaison * @return Capsule */ public function setIdMaison($idMaison) { $this->idMaison = $idMaison; return $this; } /** * Get idMaison * * @return integer */ public function getIdMaison() { return $this->idMaison; } /** * Set coteCaps * * @param integer $coteCaps * @return Capsule */ public function setCoteCaps($coteCaps) { $this->coteCaps = $coteCaps; return $this; } /** * Get coteCaps * * @return integer */ public function getCoteCaps() { return $this->coteCaps; } /** * Set coteAnneeCaps * * @param integer $coteAnneeCaps * @return Capsule */ public function setCoteAnneeCaps($coteAnneeCaps) { $this->coteAnneeCaps = $coteAnneeCaps; return $this; } /** * Get coteAnneeCaps * * @return integer */ public function getCoteAnneeCaps() { return $this->coteAnneeCaps; } /** * Set serieCaps * * @param string $serieCaps * @return Capsule */ public function setSerieCaps($serieCaps) { $this->serieCaps = $serieCaps; return $this; } /** * Get serieCaps * * @return string */ public function getSerieCaps() { return $this->serieCaps; } /** * Set couleurCaps * * @param string $couleurCaps * @return Capsule */ public function setCouleurCaps($couleurCaps) { $this->couleurCaps = $couleurCaps; return $this; } /** * Get couleurCaps * * @return string */ public function getCouleurCaps() { return $this->couleurCaps; } /** * Set diamCaps * * @param string $diamCaps * @return Capsule */ public function setDiamCaps($diamCaps) { $this->diamCaps = $diamCaps; return $this; } /** * Get diamCaps * * @return string */ public function getDiamCaps() { return $this->diamCaps; } /** * Set encocheCaps * * @param string $encocheCaps * @return Capsule */ public function setEncocheCaps($encocheCaps) { $this->encocheCaps = $encocheCaps; return $this; } /** * Get encocheCaps * * @return string */ public function getEncocheCaps() { return $this->encocheCaps; } /** * Set estampeeCaps * * @param string $estampeeCaps * @return Capsule */ public function setEstampeeCaps($estampeeCaps) { $this->estampeeCaps = $estampeeCaps; return $this; } /** * Get estampeeCaps * * @return string */ public function getEstampeeCaps() { return $this->estampeeCaps; } /** * Set insertCaps * * @param string $insertCaps * @return Capsule */ public function setInsertCaps($insertCaps) { $this->insertCaps = $insertCaps; return $this; } /** * Get insertCaps * * @return string */ public function getInsertCaps() { return $this->insertCaps; } /** * Set languetteCaps * * @param string $languetteCaps * @return Capsule */ public function setLanguetteCaps($languetteCaps) { $this->languetteCaps = $languetteCaps; return $this; } /** * Get languetteCaps * * @return string */ public function getLanguetteCaps() { return $this->languetteCaps; } /** * Set photoCaps * * @param string $photoCaps * @return Capsule */ public function setPhotoCaps($photoCaps) { $this->photoCaps = $photoCaps; return $this; } /** * Get photoCaps * * @return string */ public function getPhotoCaps() { return $this->photoCaps; } }Voila en espérant que quelqu'un puisse m'aider, c'est pour un projet de stage, je suis étudiant en BTS SIO! Je débute sur symfony 2, merci beaucoup!
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 <?php namespace SymfonyCapsule\CapsuleBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Maison * * @ORM\Table(name="maison") * @ORM\Entity */ class Maison { /** * @var integer * * @ORM\Column(name="id_maison", type="integer", nullable=false) * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ private $idMaison; /** * @var string * * @ORM\Column(name="nom_maison", type="string", length=100, nullable=false) */ private $nomMaison; /** * Get idMaison * * @return integer */ public function getIdMaison() { return $this->idMaison; } /** * Set nomMaison * * @param string $nomMaison * @return Maison */ public function setNomMaison($nomMaison) { $this->nomMaison = $nomMaison; return $this; } /** * Get nomMaison * * @return string */ public function getNomMaison() { return $this->nomMaison; } }
Partager