Bonjour,
voila je dois faire un formulaire imbriqué avec 4 Entité ( City, Post, Employer et Temp ) que je dois stocker en BDD voila a quoi il ressemble:
City, Post, Employer sont des EntityType et temps juste un Texte type.
Mais voila quand je clique sur valider je recoi un message d'erreur du style :
mon probleme je crois est que mes Entity sont pas relier par des relation ( oneToOne etc...) .
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 An exception occurred while executing 'INSERT INTO city (City) VALUES (?)' with params [null]: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'City' cannot be null
je sais pas comment my prendre a ce sujet, pourriez vous m'aidé s'il vous plait? je suis vraiment pas doué a ce sujet pourtant il parait que c'est assez simple.
controller :
twig :
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 public function indexAction(Request $request){ $employer = new Employer(); $formEmployer = $this->get('form.factory')->create(EmployerType::class, $employer); $poste = new Poste(); $formPoste = $this->get('form.factory')->create(PosteType::class, $poste ); $city = new City(); $formCity = $this->get('form.factory')->create(CityType::class, $city); $temps = new Temps(); $formTemps = $this->get('form.factory')->create(TempsType::class, $temps); //Acces au service Doctrine $doctrine = $this->container->get('doctrine'); $em = $doctrine->getManager(); if ($formCity && $formEmployer && $formPoste && $formTemps->handleRequest($request)->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($city, $poste, $employer , $temps); $em->flush(); } return $this->render('stat/projectSheet.html.twig', array( 'employer' => $formEmployer->createView(), 'city' => $formCity->createView(), 'poste' => $formPoste->createView(), 'temp' => $formTemps->createView(), )); }
merci .
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 {{ form_start(city) }} {{ form_start(poste) }} {{ form_start(employer) }} <table class="table table-bordered table-striped table-condensed"> <thead> <tr> <th>Name</th> <th>Temps</th> <th>Poste</th> <th>Ville</th> <th> Edit</th> </tr> <tr> <th>{{ form_widget(employer) }}</th> <th>{{ form_widget(temp) }}</th> <th> {{ form_widget(poste) }}</th> <th>{{ form_widget(city) }}</th> </tr> </thead> <tbody> </table> <input type="submit" value="valider"/> {{ form_end(employer) }} {{ form_end(poste) }} {{ form_end(city) }}
Partager