Bonjour à tous :)
Je suis ici pour lancer un appel à l'aide car je suis bloqué depuis hier sur le même problème et malgré mes recherches, pas moyen de me débloquer :arf:
Pour vous expliquer brièvement le contexte, j'ai deux entités "Lieu" et "Caracteristique".
Chaque Lieu (ex.: Decathlon Paris rive gauche) peut avoir 0, 1 ou plusieurs Caracteristiques (ex.: magasin, sport).
J'ai donc mes 2 entités dont voici le code :
Lieu.php
Caracteristique.phpCode:
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 <?php namespace XXX\MainBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; /** * XXX\MainBundle\Entity\Lieu * * @ORM\Table() * @ORM\Entity(repositoryClass="XXX\MainBundle\Entity\LieuRepository") */ class Lieu { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string $nom * * @ORM\Column(name="nom", type="string", length=120) */ private $nom; /** * @var decimal $latitude * * @ORM\Column(name="latitude", type="decimal", precision="20", scale="17") */ private $latitude; /** * @var decimal $longitude * * @ORM\Column(name="longitude", type="decimal", precision="20", scale="17") */ private $longitude; /** * @var integer $loc_precision * * @ORM\Column(name="loc_precision", type="integer", nullable="true") */ private $loc_precision; /** * @ORM\Column(name="caracteristiques", type="array", nullable="true") * @ORM\ManyToOne(targetEntity="XXX\MainBundle\Entity\Caracteristique", cascade={"persist"}) */ private $caracteristiques; /** * Constructeur */ public function __construct() { $this->caracteristiques = new ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set nom * * @param string $nom */ public function setNom($nom) { $this->nom = $nom; } /** * Get nom * * @return string */ public function getNom() { return $this->nom; } /** * Set latitude * * @param decimal $latitude */ public function setLatitude($latitude) { $this->latitude = $latitude; } /** * Get latitude * * @return decimal */ public function getLatitude() { return $this->latitude; } /** * Set longitude * * @param decimal $longitude */ public function setLongitude($longitude) { $this->longitude = $longitude; } /** * Get longitude * * @return decimal */ public function getLongitude() { return $this->longitude; } /** * Set loc_precision * * @param integer $locPrecision */ public function setLocPrecision($locPrecision) { $this->loc_precision = $locPrecision; } /** * Get loc_precision * * @return integer */ public function getLocPrecision() { return $this->loc_precision; } /** * Add caracteristique * * @param Caracteristique $caracteristique */ public function addCaracteristique(Caracteristique $caracteristique) { $this->caracteristiques[] = $caracteristique; } /** * Set caracteristiques */ public function setCaracteristiques(ArrayCollection $caracteristiques) { $this->caracteristiques = $caracteristiques; } /** * Get caracteristiques */ public function getCaracteristiques() { return $this->caracteristiques; } }
A partir de ça, j'ai voulu générer un CRUD (en utilisant la console) de mon entité Lieu.Code:
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 <?php namespace XXX\MainBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; /** * XXX\MainBundle\Entity\Caracteristique * * @ORM\Table() * @ORM\Entity(repositoryClass="XXX\MainBundle\Entity\CaracteristiqueRepository") */ class Caracteristique { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string $nom * * @ORM\Column(name="nom", type="string", length=100) */ private $nom; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set nom * * @param string $nom */ public function setNom($nom) { $this->nom = $nom; } /** * Get nom * * @return string */ public function getNom() { return $this->nom; } }
J'arrive à ajouter un nouveau Lieu (méthode create), afficher ses données (méthode read), l'effacer ( méthode delete), mais pas à l'éditer (méthode edit) !!!
Voici l'erreur qui ressort lorsque je vais sur ma page http://localhost/XXX/web/app_dev.php/lieu/crud/3/edit :
L'erreur est connue d'après ce que je vois sur les différents forums mais y'a rien à faire, je dois oublier quelque chose...Citation:
Entities passed to the choice field must be managed
Voici les codes de mes 2 controllers, ainsi que mon formulaire pour le Lieu.
LieuController.php
CaracteristiqueController.phpCode:
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 <?php namespace XXX\MainBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use XXX\MainBundle\Entity\Lieu; use XXX\MainBundle\Form\LieuType; /** * Lieu controller. * */ class LieuController extends Controller { /** * Lists all Lieu entities. * */ public function indexAction() { $em = $this->getDoctrine()->getEntityManager(); $entities = $em->getRepository('XXXMainBundle:Lieu')->findAll(); return $this->render('XXXMainBundle:Lieu:index.html.twig', array( 'entities' => $entities )); } /** * Finds and displays a Lieu entity. * */ public function showAction($id) { $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('XXXMainBundle:Lieu')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Lieu entity.'); } $deleteForm = $this->createDeleteForm($id); return $this->render('XXXMainBundle:Lieu:show.html.twig', array( 'entity' => $entity, 'delete_form' => $deleteForm->createView(), )); } /** * Displays a form to create a new Lieu entity. * */ public function newAction() { $entity = new Lieu(); $form = $this->createForm(new LieuType(), $entity); return $this->render('XXXMainBundle:Lieu:new.html.twig', array( 'entity' => $entity, 'form' => $form->createView() )); } /** * Creates a new Lieu entity. * */ public function createAction() { $entity = new Lieu(); $request = $this->getRequest(); $form = $this->createForm(new LieuType(), $entity); $form->bindRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('lieu_show', array('id' => $entity->getId()))); } return $this->render('XXXMainBundle:Lieu:new.html.twig', array( 'entity' => $entity, 'form' => $form->createView() )); } /** * Displays a form to edit an existing Lieu entity. * */ public function editAction($id) { $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('XXXMainBundle:Lieu')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Lieu entity.'); } $editForm = $this->createForm(new LieuType(), $entity); $deleteForm = $this->createDeleteForm($id); return $this->render('XXXMainBundle:Lieu:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); } /** * Edits an existing Lieu entity. * */ public function updateAction($id) { $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('XXXMainBundle:Lieu')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Lieu entity.'); } $editForm = $this->createForm(new LieuType(), $entity); $deleteForm = $this->createDeleteForm($id); $request = $this->getRequest(); $editForm->bindRequest($request); if ($editForm->isValid()) { $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('lieu_edit', array('id' => $id))); } return $this->render('XXXMainBundle:Lieu:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); } /** * Deletes a Lieu entity. * */ public function deleteAction($id) { $form = $this->createDeleteForm($id); $request = $this->getRequest(); $form->bindRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('XXXMainBundle:Lieu')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Lieu entity.'); } $em->remove($entity); $em->flush(); } return $this->redirect($this->generateUrl('lieu')); } private function createDeleteForm($id) { return $this->createFormBuilder(array('id' => $id)) ->add('id', 'hidden') ->getForm() ; } }
LieuType.phpCode:
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 <?php namespace XXX\MainBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use XXX\MainBundle\Entity\Caracteristique; use XXX\MainBundle\Form\CaracteristiqueType; /** * Caracteristique controller. * */ class CaracteristiqueController extends Controller { /** * Lists all Caracteristique entities. * */ public function indexAction() { $em = $this->getDoctrine()->getEntityManager(); $entities = $em->getRepository('XXXMainBundle:Caracteristique')->findAll(); return $this->render('XXXMainBundle:Caracteristique:index.html.twig', array( 'entities' => $entities )); } /** * Finds and displays a Caracteristique entity. * */ public function showAction($id) { $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('XXXMainBundle:Caracteristique')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Caracteristique entity.'); } $deleteForm = $this->createDeleteForm($id); return $this->render('XXXMainBundle:Caracteristique:show.html.twig', array( 'entity' => $entity, 'delete_form' => $deleteForm->createView(), )); } /** * Displays a form to create a new Caracteristique entity. * */ public function newAction() { $entity = new Caracteristique(); $form = $this->createForm(new CaracteristiqueType(), $entity); return $this->render('XXXMainBundle:Caracteristique:new.html.twig', array( 'entity' => $entity, 'form' => $form->createView() )); } /** * Creates a new Caracteristique entity. * */ public function createAction() { $entity = new Caracteristique(); $request = $this->getRequest(); $form = $this->createForm(new CaracteristiqueType(), $entity); $form->bindRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('caracteristique_show', array('id' => $entity->getId()))); } return $this->render('XXXMainBundle:Caracteristique:new.html.twig', array( 'entity' => $entity, 'form' => $form->createView() )); } /** * Displays a form to edit an existing Caracteristique entity. * */ public function editAction($id) { $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('XXXMainBundle:Caracteristique')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Caracteristique entity.'); } $editForm = $this->createForm(new CaracteristiqueType(), $entity); $deleteForm = $this->createDeleteForm($id); return $this->render('XXXMainBundle:Caracteristique:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); } /** * Edits an existing Caracteristique entity. * */ public function updateAction($id) { $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('XXXMainBundle:Caracteristique')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Caracteristique entity.'); } $editForm = $this->createForm(new CaracteristiqueType(), $entity); $deleteForm = $this->createDeleteForm($id); $request = $this->getRequest(); $editForm->bindRequest($request); if ($editForm->isValid()) { $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('caracteristique_edit', array('id' => $id))); } return $this->render('XXXMainBundle:Caracteristique:edit.html.twig', array( 'entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); } /** * Deletes a Caracteristique entity. * */ public function deleteAction($id) { $form = $this->createDeleteForm($id); $request = $this->getRequest(); $form->bindRequest($request); if ($form->isValid()) { $em = $this->getDoctrine()->getEntityManager(); $entity = $em->getRepository('XXXMainBundle:Caracteristique')->find($id); if (!$entity) { throw $this->createNotFoundException('Unable to find Caracteristique entity.'); } $em->remove($entity); $em->flush(); } return $this->redirect($this->generateUrl('caracteristique')); } private function createDeleteForm($id) { return $this->createFormBuilder(array('id' => $id)) ->add('id', 'hidden') ->getForm() ; } }
Je commence à désespérer... :(Code:
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 <?php namespace XXX\MainBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilder; use XXX\MainBundle\Entity\CaracteristiqueRepository; class LieuType extends AbstractType { public function buildForm(FormBuilder $builder, array $options) { $builder ->add('nom') ->add('latitude') ->add('longitude') ->add('loc_precision') ->add('caracteristiques', 'entity', array( 'class' => 'XXX\MainBundle\Entity\Caracteristique', 'property' => 'nom', 'multiple' => true, 'required' => false)); } public function getName() { return 'XXX_mainbundle_lieutype'; } }
Si quelqu'un pouvait m'aider, je lui en serai extrêmenent reconnaissant :)