Bonjour,
Je veux enregistrer l id d'une autre table qui je l'ai recupérer mais j'arrive pas.En fait j'ai 2 entités(Avv,Organisation) quand j'ajoute les données de ma table organisation je veux aussi ajouter id de ma table Avv.
id_avv est un foreign key pour la table organisation
code d'ajouter organisation dans mon controleur:
mon entity organisation.php
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 public function organisationAction($id=null){ $message=''; $Organisation = new Organisation(); //$form = $this->container->get('form.factory')->create(new AvvForm(), $Avv); $form = $this->createFormBuilder($Organisation) ->add('tache', 'text') ->add('personne', 'text') ->add('date_realisation', 'date', array( 'empty_value' => array('year' => 'Year', 'month' => 'Month', 'day' => 'Day'), 'required' => false )) //->add('dateReponse', 'birthday', array('label' => 'Date de reponse')) ->getForm(); $request = $this->container->get('request'); //$desk = $this->getDoctrine()->getRepository('WmdWatchMyDeskBundle:Desk')->find($id); //08.echo "Le bureau récupéré porte l'ID: ".$desk->getId()." et le titre: ".$desk->getTitle(); $id = $request->get('id'); //$id=$this->getDoctrine()->getRepository('MyAppAvvBundle:Avv')->find($id); if ($request->getMethod() == 'POST') { $form->bindRequest($request); if ($form->isValid()) { $em = $this->container->get('doctrine')->getEntityManager(); $Organisation->setAvv($id); var_dump($id); $em->persist($Organisation); $em->flush(); $message='Org ajouté avec succès !'; } } return $this->container->get('templating')->renderResponse( 'MyAppAvvBundle:Default:organisation.html.twig', array( 'form' => $form->createView(), 'message' => $message, )); //return $this->container->get('templating')->renderResponse('MyAppAvvBundle:Default:lancement.html.twig'); }
Merci d'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 <?php namespace MyApp\AvvBundle\Entity; use Symfony\Component\Validator\Constraints\Date; use Doctrine\ORM\Mapping as ORM; /** * MyApp\AvvBundle\Entity\Organisation * * @ORM\Table() * @ORM\Entity */ class Organisation { /** * @var integer $id * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var text $tache * * @ORM\Column(name="tache", type="text") */ private $tache; /** * @var text $personne * * @ORM\Column(name="personne", type="text") */ private $personne; /** * @var Date $date_realisation * * @ORM\Column(name="date_realisation", type="date") */ private $date_realisation; /** * @ORM\ManyToOne(targetEntity="Avv", inversedBy="Organisation") * @ORM\JoinColumn(name="avv_id", referencedColumnName="id") */ protected $avv; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set tache * * @param text $tache */ public function setTache($tache) { $this->tache = $tache; } /** * Get tache * * @return text */ public function getTache() { return $this->tache; } /** * Set personne * * @param text $personne */ public function setPersonne($personne) { $this->personne = $personne; } /** * Get personne * * @return text */ public function getPersonne() { return $this->personne; } /** * Set avv * * @param MyApp\AvvBundle\Entity\Avv $avv */ public function setAvv(\MyApp\AvvBundle\Entity\Avv $avv) { $this->avv = $avv; } /** * Get avv * * @return MyApp\AvvBundle\Entity\Avv */ public function getAvv() { return $this->avv; } /** * Set date_realisation * * @param date $dateRealisation */ public function setDateRealisation($dateRealisation) { $this->date_realisation = $dateRealisation; } /** * Get date_realisation * * @return date */ public function getDateRealisation() { return $this->date_realisation; } }
Partager