Bonjour,
Je souhaite imbriquer 2 formulaires... un formulaire représentant un "pays" et un sous formulaire pour saisir l'initial du pays sur la même page...
J'arrive bien à enregistré le pays en bdd, mais pas le paysinitial correspondant.
Mes entités :
Pays : Je ne m'en sers que pour l'id
Mon entité PaysInitial
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 <?php namespace Opengen\GeoBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Pays * * @ORM\Table() * @ORM\Entity(repositoryClass="Opengen\GeoBundle\Entity\PaysRepository") */ class Pays { /** * @ORM\OneToMany(targetEntity="Opengen\GeoBundle\Entity\PaysInitial" , cascade={"persist"} , mappedBy="pays") * */ private $paysinitials; /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * Constructor */ public function __construct() { $this->PaysInitials = new \Doctrine\Common\Collections\ArrayCollection(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Add paysinitials * * @param \Opengen\GeoBundle\Entity\PaysInitial $paysinitials * @return Pays */ public function addPaysinitial(\Opengen\GeoBundle\Entity\PaysInitial $paysinitials) { $this->paysinitials[] = $paysinitials; return $this; } /** * Remove paysinitials * * @param \Opengen\GeoBundle\Entity\PaysInitial $paysinitials */ public function removePaysinitial(\Opengen\GeoBundle\Entity\PaysInitial $paysinitials) { $this->paysinitials->removeElement($paysinitials); } /** * Get paysinitials * * @return \Doctrine\Common\Collections\Collection */ public function getPaysinitials() { return $this->paysinitials; } }
Mon formulaire paysInitialType
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 <?php namespace Opengen\GeoBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * PaysNom * * @ORM\Table() * @ORM\Entity(repositoryClass="Opengen\GeoBundle\Entity\PaysInitialRepository") */ class PaysInitial { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @ORM\ManyToOne(targetEntity="Opengen\GeoBundle\Entity\Pays",inversedBy="paysinitials" ) * * @ORM\JoinColumn(nullable=false) */ private $pays; /** * @var \DateTime * * @ORM\Column(name="date", type="datetime") */ private $date; /** * @var string * * @ORM\Column(name="initial", type="string", length=10) */ private $initial; /** * @var boolean * * @ORM\Column(name="visible", type="boolean" ) */ private $visible; /** * @var integer * * @ORM\Column(name="user", type="integer" ) */ private $user; public function __construct() { $this->date = new \Datetime(); $this->visible = 1 ; $this->user = 1 ; } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set date * * @param \DateTime $date * @return PaysInitial */ public function setDate($date) { $this->date = $date; return $this; } /** * Get date * * @return \DateTime */ public function getDate() { return $this->date; } /** * Set initial * * @param string $initial * @return PaysInitial */ public function setInitial($initial) { $this->initial = $initial; return $this; } /** * Get initial * * @return string */ public function getInitial() { return $this->initial; } /** * Set visible * * @param boolean $visible * @return PaysInitial */ public function setVisible($visible) { $this->visible = $visible; return $this; } /** * Get visible * * @return boolean */ public function getVisible() { return $this->visible; } /** * Set user * * @param integer $user * @return PaysInitial */ public function setUser($user) { $this->user = $user; return $this; } /** * Get user * * @return integer */ public function getUser() { return $this->user; } /** * Set pays * * @param \Opengen\GeoBundle\Entity\Pays $pays * @return PaysInitial */ public function setPays(\Opengen\GeoBundle\Entity\Pays $pays) { $this->pays = $pays; return $this; } /** * Get pays * * @return \Opengen\GeoBundle\Entity\Pays */ public function getPays() { return $this->pays; } }
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 <?php namespace Opengen\GeoBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class PaysInitialType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add('initial','text') ; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Opengen\GeoBundle\Entity\PaysInitial' )); } public function getName() { return 'opengen_geobundle_paysinitialtype'; } }
Mon formulaire PaysType
Dans mon contrôleur j'ai ça :
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 <?php namespace Opengen\GeoBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolverInterface; class PaysType extends AbstractType { public function buildForm(FormBuilderInterface $builder, array $options) { $builder // Rajoutez cette ligne ->add('PaysInitials', new PaysInitialType()) ; } public function setDefaultOptions(OptionsResolverInterface $resolver) { $resolver->setDefaults(array( 'data_class' => 'Opengen\GeoBundle\Entity\Pays' )); } public function getName() { return 'opengen_geobundle_paystype'; } }
Mon formulaire s'affiche bien mais quand je valide, le pays est bien enregistré en bdd mais rien dans ma table "paysinitial"
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 $pays = new Pays(); $form = $this->createForm(new PaysType, $pays); $request = $this->get('request'); if( $request->getMethod() == 'POST' ) { $form->bind($request); if( $form->isValid() ) { $em = $this->getDoctrine()->getEntityManager(); $em->persist($pays); $em->flush(); var_dump ($pays);
et var_dump m'affiche :
Si quelqu'un sait pourquoi mon entité paysinitila n'est pas enregistré en bdd, ça serait cool... ça fait un peu 3 jours que je bloque là dessus :-(
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 object(Opengen\GeoBundle\Entity\Pays)[75] private 'paysinitials' => null private 'id' => int 104 public 'PaysInitials' => object(Opengen\GeoBundle\Entity\PaysInitial)[277] private 'id' => null private 'pays' => null private 'date' => object(DateTime)[275] public 'date' => string '2013-04-22 19:51:12' (length=19) public 'timezone_type' => int 3 public 'timezone' => string 'UTC' (length=3) private 'initial' => string 'lmjkm' (length=5) private 'visible' => int 1 private 'user' => int 1
Merci
Partager