Bonjour,
J'ai mon entité Uzer, propriétaire de la relation M2M avec mon entité conso.
J'ai mon entité consos, propriétaire de la relation M2M avec presta.
Je souhaite créer un formulaire pour rajouter des consos.
J'obtiens l'erreur:
Je comprend qu'il s'agit de manque de méthode mais comme presta est un array collection dans l'entité conso il a comme méthodes celles lui correspondant (add / remove / get). Pourquoi est ce que j'obtiens cette erreurs ...
Code : Sélectionner tout - Visualiser dans une fenêtre à part Property "prestas" is not public in class "SB\ConsoBundle\Entity\Conso". Maybe you should create the method "setPrestas()"?
Mon constructeur de form d'entité conso:
voici mon entité conso
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 <?php namespace SB\ConsoBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class ConsoType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('dateprevue', 'datetime') ->add('souhait', 'checkbox', array('required' => false)) ->add('fait', 'checkbox', array('required' => false)) ->add('paye', 'checkbox', array('required' => false)) ->add('comment', 'textarea', array('required' => false)) ->add('prestas', 'entity', array( 'class' => 'SBPrestaBundle:Presta', 'property' => 'title', 'expanded' => false, 'multiple' => false, 'label' => false, 'required' => false)) ; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'SB\ConsoBundle\Entity\Conso' )); } public function getName() { return 'sb_consobundle_consotype'; } }
Mon controleur:
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 <?php namespace SB\ConsoBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Conso * * @ORM\Table() * @ORM\Entity(repositoryClass="SB\ConsoBundle\Entity\ConsoRepository") */ class Conso { /** * @ORM\ManyToMany(targetEntity="SB\PrestaBundle\Entity\Presta") */ private $prestas; /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var \DateTime * * @ORM\Column(name="dateprevue", type="datetime") */ private $dateprevue; /** * @var boolean * * @ORM\Column(name="fait", type="boolean") */ private $fait; /** * @var boolean * * @ORM\Column(name="souhait", type="boolean") */ private $souhait; /** * @var boolean * * @ORM\Column(name="paye", type="boolean") */ private $paye; /** * @var string * * @ORM\Column(name="comment", type="text") */ private $comment; /** * Constructor */ public function __construct() { $this->prestas = new \Doctrine\Common\Collections\ArrayCollection(); $this->fait = false; $this->paye = false; } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set dateprevue * * @param \DateTime $dateprevue * @return Conso */ public function setDateprevue($dateprevue) { $this->dateprevue = $dateprevue; return $this; } /** * Get dateprevue * * @return \DateTime */ public function getDateprevue() { return $this->dateprevue; } /** * Set fait * * @param boolean $fait * @return Conso */ public function setFait($fait) { $this->fait = $fait; return $this; } /** * Get fait * * @return boolean */ public function getFait() { return $this->fait; } /** * Set paye * * @param boolean $paye * @return Conso */ public function setPaye($paye) { $this->paye = $paye; return $this; } /** * Get paye * * @return boolean */ public function getPaye() { return $this->paye; } /** * Set comment * * @param string $comment * @return Conso */ public function setComment($comment) { $this->comment = $comment; return $this; } /** * Get comment * * @return string */ public function getComment() { return $this->comment; } /** * Add prestas * * @param \SB\PrestaBundle\Entity\Presta $prestas * @return Conso */ public function addPresta(\SB\PrestaBundle\Entity\Presta $prestas) { $this->prestas[] = $prestas; return $this; } /** * Remove prestas * * @param \SB\PrestaBundle\Entity\Presta $prestas */ public function removePresta(\SB\PrestaBundle\Entity\Presta $prestas) { $this->prestas->removeElement($prestas); } /** * Get prestas * * @return \Doctrine\Common\Collections\Collection */ public function getPrestas() { return $this->prestas; } /** * Set souhait * * @param boolean $souhait * @return Conso */ public function setSouhait($souhait) { $this->souhait = $souhait; return $this; } /** * Get souhait * * @return boolean */ public function getSouhait() { return $this->souhait; } }
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 newAction($id) { $conso = new Conso(); $repository = $this->getDoctrine() ->getManager() ->getRepository('SBUserBundle:Uzer'); $uzer = $repository->find($id); $form = $this->createForm(new ConsoType, $conso); $request = $this->get('request'); if ($request->getMethod() == 'POST') { $uzer->addConso($conso); $form->bind($request); if ($form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($uzer); $em->flush(); $this->get('session')->getFlashBag()->add('info', 'Conso bien rajoutée'); return $this->redirect($this->generateUrl('uzer_gest_view_user', array('id' => $id))); } } return $this->render('SBConsoBundle:ConsoGest:newconso.html.twig', array('form' => $form->createView(),'id' => $id)); }
Partager