Bonjour,
Pour l'intitulé du post je suis désolé j'ai pas su ciomment tourner ma phrase
J'ai une entité Voyage relié à une entité Ville et une entité User
Sur une page de résultat suite à la soumission d'un formulaire je voudrait lister les voyages avec les infos des villes de départs et d'arrivée et également les infos des usersd qui ont soumis ces voyages.
en gros j'ai une url du type: result?depart=Paris&arrivee=Madrid.
je vous joins le code de l'action commenté pour récupérer cette la liste des voyages correspondant:Comme il est commenté dans ce bout de code, j'arrive parfaitement à lister les voyages selon les parametres d'url mais je n'arrive pas à récupérer les infos des users qui ont soumis ces voyages.
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 <?php public function resultAction(Request $request) { //recup du premier paramètre d'url correspondant à la ville de depart $searchdepart = $request->query->get('search'); //recup du premier paramètre d'url correspondant à la ville d'arrivée $searcharrivee = $request->query->get('search1'); // On récupère l'EntityManager $em = $this->getDoctrine() ->getManager(); //recup ville de depart dans l'entity Town selon le paramètre d'url correspondant à la ville de depart $departs = $em->getRepository('MonprojetVoyageBundle:Town') ->findOneBy(array('ascc' => $searchdepart)); //recup ville d'arrivée Dans l'entity Town selon le paramètre d'url correspondant à la ville d'arrivée $arrivees = $em->getRepository('MonprojetVoyageBundle:Town') ->findOneBy(array('ascc' => $searcharrivee)); // On récupère les voyages dans l'entité Voyages correspondant au critères de ville de départs et d'arrivées $Voyage = $em->getRepository('MonprojetVoyageBundle:Voyage') ->findBy(array('towns' => $departs,'towns2'=> $arrivees), array('dateDebut' => 'desc'), 5, 0); //jusquici si je vais une boucle dans ma vue twig j'obtiens bien la liste des voyages corrspondant aux critères donc $voyage n'est pasz null //le hic c'est que je veux également récupérer les infos des uers qui ont soumis ces voyaegs donc je fais: //je récupère les users de l'entity users correspondant au voyages de $voyages: $users = $em->getRepository('MonprojetUserBundle:Users') ->find($Voyage->getUsers()); //Or c'est là que ça coince j'obtiens cette erreur:ContextErrorException: Notice: Trying to get property of non-object in C:\wamp\www\Symfony.... // Ou null si aucun article n'a été trouvé avec l'id $id if($Voyage === null) { throw $this->createNotFoundException('Voyage[id='.$id.'] inexistant.'); } return $this->render('MonprojetVoyageBundle:Voyage:result.html.twig', array('arrivee' =>$arrivees ,'depart' =>$departs ,'Voyage' => $Voyage )); }
Quelq'un aurait il une piste.
Je précise que voyage et user sont bien en relation many-to one et one to many.
Mon entity voyage:
et mon entity users:
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396 <?php namespace Monprojet\VoyageBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Voyage * * @ORM\Table() * @ORM\Entity(repositoryClass="Monprojet\VoyageBundle\Entity\VoyageRepository") */ class Voyage { /** * @ORM\ManyToOne(targetEntity="Monprojet\VoyageBundle\Entity\Town", inversedBy="Voyages") * @ORM\JoinColumn(nullable=false) */ private $towns; /** * @ORM\ManyToOne(targetEntity="Monprojet\VoyageBundle\Entity\Town", inversedBy="Voyages2") * @ORM\JoinColumn(nullable=false) */ private $towns2; /** * @ORM\ManyToOne(targetEntity="Monprojet\UserBundle\Entity\Users", inversedBy="Voyages") * @ORM\JoinColumn(nullable=false) */ private $users; /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var \DateTime * * @ORM\Column(name="date_debut", type="date") */ private $dateDebut; /** * @var \DateTime * * @ORM\Column(name="heure", type="time") */ private $heure; /** * @var string * * @ORM\Column(name="type", type="string", length=255) */ private $type; /** * @var string * * @ORM\Column(name="dir", type="string", length=255) */ private $dir; /** * @var string * * @ORM\Column(name="pds", type="string", length=255) */ private $pds; /** * @var string * * @ORM\Column(name="comment", type="string", length=255) */ private $comment; /** * @var string * * @ORM\Column(name="price", type="string", length=255) */ private $price; /** * @var integer * * @ORM\Column(name="active", type="integer") */ private $active; /** * @ORM\Column(name="publication", type="date") */ private $publication; public function __construct() { $this->publication = new \Datetime(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set dateDebut * * @param \DateTime $dateDebut * @return Voyage */ public function setDateDebut($dateDebut) { $this->dateDebut = $dateDebut; return $this; } /** * Get dateDebut * * @return \DateTime */ public function getDateDebut() { return $this->dateDebut; } /** * Set heure * * @param \DateTime $heure * @return Voyage */ public function setHeure($heure) { $this->heure = $heure; return $this; } /** * Get heure * * @return \DateTime */ public function getHeure() { return $this->heure; } /** * Set type * * @param string $type * @return Voyage */ public function setType($type) { $this->type = $type; return $this; } /** * Get type * * @return string */ public function getType() { return $this->type; } /** * Set dir * * @param string $dir * @return Voyage */ public function setDir($dir) { $this->dir = $dir; return $this; } /** * Get dir * * @return string */ public function getDir() { return $this->dir; } /** * Set pds * * @param string $pds * @return Voyage */ public function setPds($pds) { $this->pds = $pds; return $this; } /** * Get pds * * @return string */ public function getPds() { return $this->pds; } /** * Set comment * * @param string $comment * @return Voyage */ public function setComment($comment) { $this->comment = $comment; return $this; } /** * Get comment * * @return string */ public function getComment() { return $this->comment; } /** * Get price * * @return string */ public function getPrice() { return $this->price; } /** * Set active * * @param integer $active * @return Voyage */ public function setActive($active) { $this->active = $active; return $this; } /** * Get active * * @return integer */ public function getActive() { return $this->active; } /** * Set publication * * @param \DateTime $publication * @return Voyage */ public function setPublication($publication) { $this->publication = $publication; return $this; } /** * Get publication * * @return \DateTime */ public function getPublication() { return $this->publication; } /** * Set price * * @param string $price * @return Voyage */ public function setPrice($price) { $this->price = $price; return $this; } /** * Set users * * @param \Monprojet\UserBundle\Entity\Users $users * @return Voyage */ public function setUsers(\Monprojet\UserBundle\Entity\Users $users) { $this->users = $users; return $this; } /** * Get users * * @return \Monprojet\UserBundle\Entity\Users */ public function getUsers() { return $this->users; } /** * Set towns * * @param \Monprojet\VoyageBundle\Entity\Town $towns * @return Voyage */ public function setTowns(\Monprojet\VoyageBundle\Entity\Town $towns) { $this->towns = $towns; return $this; } /** * Get towns * * @return \Monprojet\VoyageBundle\Entity\Town */ public function getTowns() { return $this->towns; } /** * Set towns2 * * @param \Monprojet\VoyageBundle\Entity\Town $towns2 * @return Voyage */ public function setTowns2(\Monprojet\VoyageBundle\Entity\Town $towns2) { $this->towns2 = $towns2; return $this; } /** * Get towns2 * * @return \Monprojet\VoyageBundle\Entity\Town */ public function getTowns2() { return $this->towns2; } }
Un grand merci par avance.
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 <?php namespace Monprojet\UserBundle\Entity; use Doctrine\ORM\Mapping as ORM; use FOS\UserBundle\Entity\User as BaseUser; /** * Users * * @ORM\Table() * @ORM\Entity(repositoryClass="Monprojet\UserBundle\Entity\UsersRepository") */ class Users extends BaseUser { /** * @ORM\ManyToOne(targetEntity="Monprojet\VoyageBundle\Entity\Town", inversedBy="users") * @ORM\JoinColumn(nullable=false) */ private $towns; /** * @ORM\OneToMany(targetEntity="Monprojet\VoyageBundle\Entity\Voyage", mappedBy="users") */ private $Voyages; /** * @var string * * @ORM\Column(name="tel", type="string", length=255) */ private $tel; /** * @var string * * @ORM\Column(name="rating", type="string", length=255) */ private $rating; /** * @var \DateTime * * @ORM\Column(name="dateinscr", type="datetime") */ private $dateinscr; /** * @var string * * @ORM\Column(name="lang", type="string", length=255) */ private $lang; /** * @var string * * @ORM\Column(name="pic", type="string", length=255) */ private $pic; /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ protected $id; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Add Voyages * * @param \Monprojet\VoyageBundle\Entity\Voyage $Voyages * @return Users */ public function addVoyage(\Monprojet\VoyageBundle\Entity\Voyage $Voyages) { $this->Voyages[] = $Voyages; $Voyages->setUsers($this); return $this; } /** * Remove Voyages * * @param \Monprojet\VoyageBundle\Entity\Voyage $Voyages */ public function removeVoyage(\Monprojet\VoyageBundle\Entity\Voyage $Voyages) { $this->Voyages->removeElement($Voyages); } /** * Get Voyages * * @return \Doctrine\Common\Collections\Collection */ public function getVoyages() { return $this->Voyages; } /** * Set towns * * @param \Monprojet\VoyageBundle\Entity\Town $towns * @return Users */ public function setTowns(\Monprojet\VoyageBundle\Entity\Town $towns) { $this->towns = $towns; return $this; } /** * Get towns * * @return \Monprojet\VoyageBundle\Entity\Town */ public function getTowns() { return $this->towns; } public function __construct() { parent::__construct(); $this->Voyages = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Set tel * * @param string $tel * @return Users */ public function setTel($tel) { $this->tel = $tel; return $this; } /** * Get tel * * @return string */ public function getTel() { return $this->tel; } /** * Set rating * * @param string $rating * @return Users */ public function setRating($rating) { $this->rating = $rating; return $this; } /** * Get rating * * @return string */ public function getRating() { return $this->rating; } /** * Set dateinscr * * @param \DateTime $dateinscr * @return Users */ public function setDateinscr($dateinscr) { $this->dateinscr = $dateinscr; return $this; } /** * Get dateinscr * * @return \DateTime */ public function getDateinscr() { return $this->dateinscr; } /** * Set lang * * @param string $lang * @return Users */ public function setLang($lang) { $this->lang = $lang; return $this; } /** * Get lang * * @return string */ public function getLang() { return $this->lang; } /** * Set pic * * @param string $pic * @return Users */ public function setPic($pic) { $this->pic = $pic; return $this; } /** * Get pic * * @return string */ public function getPic() { return $this->pic; } }
Partager