-
Voici le problème qui apparaît :
Voici ma class Voiture :An exception occurred while executing 'INSERT INTO voitures (marque, modele, couleur, proprietaire) VALUES (?, ?, ?, ?)' with params ["Renault", "Clio", "Bleu", null]:
SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'proprietaire' cannot be null
Voici ma class Personne :
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 <?php namespace sio\membresBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Voitures */ class Voitures { /** * @var string */ private $immatriculation; /** * @var string */ private $marque; /** * @var string */ private $modele; /** * @var string */ private $couleur; /** * @var \sio\membresBundle\Entity\Personnes */ private $proprietaire; /** * Get immatriculation * * @return string */ public function __construct($immatriculation = 'BB234RT') { $this->immatriculation = (string)$immatriculation; } public function getImmatriculation() { return $this->immatriculation; } /** * Set marque * * @param string $marque * @return Voitures */ public function setMarque($marque) { $this->marque = $marque; return $this; } /** * Get marque * * @return string */ public function getMarque() { return $this->marque; } /** * Set modele * * @param string $modele * @return Voitures */ public function setModele($modele) { $this->modele = $modele; return $this; } /** * Get modele * * @return string */ public function getModele() { return $this->modele; } /** * Set couleur * * @param string $couleur * @return Voitures */ public function setCouleur($couleur) { $this->couleur = $couleur; return $this; } /** * Get couleur * * @return string */ public function getCouleur() { return $this->couleur; } /** * Set proprietaire * * @param \sio\membresBundle\Entity\Personnes $proprietaire * @return Voitures */ public function setProprietaire(\sio\membresBundle\Entity\Personnes $proprietaire = null) { $this->proprietaire = $proprietaire; return $this; } /** * Get proprietaire * * @return \sio\membresBundle\Entity\Personnes */ public function getProprietaire() { return $this->proprietaire; } }
Voici ma Page DefautController :
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 <?php namespace sio\membresBundle\Entity; use Doctrine\ORM\Mapping as ORM; /** * Personnes */ class Personnes { /** * @var integer */ private $id; /** * @var string */ private $nom; /** * @var string */ private $prenom; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set nom * * @param string $nom * @return Personnes */ 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 Personnes */ public function setPrenom($prenom) { $this->prenom = $prenom; return $this; } /** * Get prenom * * @return string */ public function getPrenom() { return $this->prenom; } }
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 <?php namespace sio\membresBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use sio\membresBundle\Entity\Personnes; use sio\membresBundle\Entity\Voitures; class DefaultController extends Controller { public function indexAction($name) { $personne = new Personnes; $personne -> setNom('SIOUNANDAM'); $personne -> setPrenom('Jean-Pascal'); $voiture = new Voitures; $voiture -> getImmatriculation ('BB234RT'); $voiture -> setMarque('Renault'); $voiture -> setModele ('Clio'); $voiture -> setCouleur ('Bleu'); $manager=$this->getDoctrine()->getManager(); $manager->persist ($personne); $manager->flush(); $manager=$this->getDoctrine()->getManager(); $manager->persist ($voiture); $manager->flush(); return $this->render('siomembresBundle:Default:index.html.twig', array('name' => $name, 'vous' => $personne, 'moi' => $voiture)); } }
Partager