Bonjour,
J'ai un formulaire qui contient une liste d'entitées,
Je peux sélectionner 0 ou plusieurs entitées.
Lorsque je sélectionne mes entitées pour la première fois, totu marche correctement, symfony ajoute totu correctement dans ma base.
Mais lorsque je vais sur ma page pour modifier mon formulaire (sélectionner ou déselectionner des entitées) il y a un problème si je selectionne une entité sélectionner, et bien symfony me la supprime au lieu de l'ajouter.
Est-ce que mon problème est clair ? :s
Savez vous pourquoi ? Merci.
Filieres Controller
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 public function modifierAction($id) { $repository = $this->getDoctrine()->getManager()->getRepository('MeteoApplisAdminBundle:ConfFilieres'); $filiere = $repository->find($id); $form = $this->createForm(new ConfFilieresType, $filiere, array('id' => $filiere->getId())); $request = $this->get('request'); if($request->getMethod() == 'POST') { $form->bind($request); if($form->isValid()) { $repository = $this->getDoctrine()->getManager()->getRepository('MeteoApplisAdminBundle:ConfBriques'); $briques = $repository->findByFiliere($filiere->getId()); foreach($briques as $brique) $filiere->removeBrique($brique); $selection = $form->get('briques')->getData()->toArray(); foreach($selection as $brique) $filiere->addBrique($brique); $em = $this->getDoctrine()->getEntityManager(); $em->persist($filiere); $em->flush(); return $this->redirect($this->generateUrl('meteo_applis_admin_filieres')); } } return $this->render('MeteoApplisAdminBundle:Admin:Filieres/filieres_modifier.html.twig', array( 'filiere' => $filiere, 'form' => $form->createView(), )); }
Filieres entity
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 <?php namespace MeteoApplis\AdminBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; /** * MeteoApplis\AdminBundle\Entity\ConfFilieres * * @ORM\Table() * @ORM\Entity(repositoryClass="MeteoApplis\AdminBundle\Entity\ConfFilieresRepository") * @UniqueEntity(fields="nom", message="Cette filière applicatives existe déjà.") */ class ConfFilieres { /** * @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=255, nullable=false, unique=true) * @Assert\NotBlank(message="Veuillez renseigner ce champ.") * @Assert\MaxLength(limit="255", message="Le nom de la filière ne doit pas dépasser {{ limit }}") */ private $nom; /** * @ORM\OneToMany(targetEntity="MeteoApplis\AdminBundle\Entity\ConfBriques", mappedBy="filiere") * @ORM\JoinColumn(nullable=true) */ private $briques; /** * Constructor */ public function __construct() { $this->briques = new \Doctrine\Common\Collections\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; } /** * Add brique * * @param MeteoApplis\AdminBundle\Entity\ConfBriques $brique * @return ConfFilieres */ public function addBrique(\MeteoApplis\AdminBundle\Entity\ConfBriques $brique) { $this->briques[] = $brique; $brique->setFiliere($this); return $this; } /** * Remove brique * * @param MeteoApplis\AdminBundle\Entity\ConfBriques $brique */ public function removeBrique(\MeteoApplis\AdminBundle\Entity\ConfBriques $brique) { $this->briques->removeElement($brique); $brique->setFiliere(null); } /** * Get briques * * @return Doctrine\Common\Collections\Collection */ public function getBriques() { return $this->briques; } }
Briques entity
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 <?php namespace MeteoApplis\AdminBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Doctrine\Common\Collections\ArrayCollection; use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; use Symfony\Component\Validator\Constraints as Assert; /** * MeteoApplis\AdminBundle\Entity\ConfBriques * * @ORM\Table() * @ORM\Entity(repositoryClass="MeteoApplis\AdminBundle\Entity\ConfBriquesRepository") * @UniqueEntity(fields="nom", message="Cette brique applicatives existe déjà.") */ class ConfBriques { /** * @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=255, nullable=false, unique=true) * @Assert\NotBlank(message="Veuillez renseigner ce champ.") * @Assert\MaxLength(limit="255", message="Le nom de la brique applicatives ne doit pas dépasser {{ limit }}") */ private $nom; /** * @ORM\OneToMany(targetEntity="MeteoApplis\AdminBundle\Entity\ConfApplications", mappedBy="brique") */ private $applications; /** * @ORM\ManyToOne(targetEntity="MeteoApplis\AdminBundle\Entity\ConfFilieres", inversedBy="briques") * @ORM\JoinColumn(nullable=true) */ private $filiere; /** * Constructor */ public function __construct() { $this->applications = new \Doctrine\Common\Collections\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; } /** * Add application * * @param MeteoApplis\AdminBundle\Entity\ConfApplications $application * @return ConfBriques */ public function addApplication(\MeteoApplis\AdminBundle\Entity\ConfApplications $application) { $this->applications[] = $application; return $this; } /** * Remove application * * @param MeteoApplis\AdminBundle\Entity\ConfApplications $application */ public function removeApplication(\MeteoApplis\AdminBundle\Entity\ConfApplications $application) { $this->applications->removeElement($application); } /** * Get applications * * @return Doctrine\Common\Collections\Collection */ public function getApplications() { return $this->applications; } /** * Set filiere * * @param MeteoApplis\AdminBundle\Entity\ConfFilieres $filiere */ public function setFiliere(\MeteoApplis\AdminBundle\Entity\ConfFilieres $filiere = null) { $this->filiere = $filiere; } /** * Get filiere * * @return MeteoApplis\AdminBundle\Entity\ConfFilieres */ public function getFiliere() { return $this->filiere; } }
Partager