Bonjour
j'ai mes deux entité que voici:
client
niveaux
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 <?php namespace Gestion\ClientBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Client * * @ORM\Table() * @ORM\Entity(repositoryClass="Gestion\ClientBundle\Entity\ClientRepository") */ class Client { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var \DateTime * * @ORM\Column(name="date", type="datetime") */ private $date; /** * @var string * * @ORM\Column(name="nom", type="string", length=70) */ private $nom; /** * @var string * * @ORM\Column(name="prenom", type="string", length=80) */ private $prenom; /** * @var integer * * @ORM\Column(name="telephone", type="integer") */ private $telephone; /** * @ORM\ManyToOne(targetEntity="Adminsite\BasesBundle\Entity\Niveaux") * @ORM\JoinColumn(nullable=false) */ private $niveaux; public function __construct() { $this->date = new \Datetime(); } /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set date * * @param \DateTime $date * @return Client */ public function setDate($date) { $this->date = $date; return $this; } /** * Get date * * @return \DateTime */ public function getDate() { return $this->date; } /** * Set nom * * @param string $nom * @return Client */ public function setNom($nom) { $this->nom = $nom; return $this; } /** * Get nom * * @return string */ public function getNom() { return $this->nom; } /** * Set prenom * * @param string $prenom * @return Client */ public function setPrenom($prenom) { $this->prenom = $prenom; return $this; } /** * Get prenom * * @return string */ public function getPrenom() { return $this->prenom; } /** * Set telephone * * @param integer $telephone * @return Client */ public function setTelephone($telephone) { $this->telephone = $telephone; return $this; } /** * Get telephone * * @return integer */ public function getTelephone() { return $this->telephone; } /** * Set niveaux * * @param \Adminsite\BasesBundle\Entity\Niveaux $niveaux * @return Client */ public function setNiveaux(\Adminsite\BasesBundle\Entity\Niveaux $niveaux) { $this->niveaux = $niveaux; return $this; } /** * Get niveaux * * @return \Adminsite\BasesBundle\Entity\Niveaux */ public function getNiveaux() { return $this->niveaux; } }
je cherche à faire un ajout en bdd avec ma méthode ajoutAction:
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 <?php namespace Adminsite\BasesBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Niveaux * * @ORM\Table() * @ORM\Entity(repositoryClass="Adminsite\BasesBundle\Entity\NiveauxRepository") */ class Niveaux { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="intitule", type="string", length=255) */ private $intitule; /** * @var integer * * @ORM\Column(name="classement", type="integer") */ private $classement; /** * @var string * * @ORM\Column(name="commentaires", type="string", length=255) */ private $commentaires; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set intitule * * @param string $intitule * @return Niveaux */ public function setIntitule($intitule) { $this->intitule = $intitule; return $this; } /** * Get intitule * * @return string */ public function getIntitule() { return $this->intitule; } /** * Set classement * * @param integer $classement * @return Niveaux */ public function setClassement($classement) { $this->classement = $classement; return $this; } /** * Get classement * * @return integer */ public function getClassement() { return $this->classement; } /** * Set commentaires * * @param string $commentaires * @return Niveaux */ public function setCommentaires($commentaires) { $this->commentaires = $commentaires; return $this; } /** * Get commentaires * * @return string */ public function getCommentaires() { return $this->commentaires; } }
Comment remplir le champ lié niveaux du client ?
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 <?php namespace Gestion\ClientBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Gestion\ClientBundle\Entity\Client; class GestionClientController extends Controller { public function indexAction() { $repository = $this->getDoctrine() ->getManager() ->getRepository('GestionClientBundle:Client'); /* il faudra les classer par date de dernière prestation */ $listeclientnom = $repository->findBy(array('nom' => 'udyr')); $listeclientprenom = $repository->findBy(array('prenom' => 'udyr')); return $this->render('GestionClientBundle:Default:rechGestionClient.html.twig', array('listeclientnom' => $listeclientnom, 'listeclientprenom' => $listeclientprenom )); } public function nouveauAction() { return $this->render('GestionClientBundle:Default:nouveauGestionClient.html.twig'); } public function ficheAction($id) { $repository = $this->getDoctrine() ->getManager() ->getRepository('GestionClientBundle:Client'); // On récupère l'entité correspondant à l'id $id $client = $repository->find($id); // $article est donc une instance de Sdz\BlogBundle\Entity\Article // Ou null si aucun article n'a été trouvé avec l'id $id if($client === null) { throw $this->createNotFoundException('Client[id='.$id.'] inexistant.'); } return $this->render('GestionClientBundle:Default:ficheGestionClient.html.twig', array('client' => $client)); } public function ajoutAction() { $client = new Client(); $client->setNom('ahri'); $client->setPrenom('Olaf'); $client->setTelephone('0606060606'); $client->setNiveaux($niveaux); $em = $this->getDoctrine()->getManager(); $em->persist($client); $em->flush(); return $this->redirect( $this->generateUrl('rech_client') ); } }
Partager