Bonjour,
J'ai un formulaire des des collections et je n'arrive pas a enregistrer en BDD les données saisies.
J'ai 2 entités :
Leads.php (extrait) :
Client.php
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 ** * Leads * * @ORM\Table(name="leads") * @ORM\Entity(repositoryClass="BackBundle\Repository\LeadsRepository") */ class Leads { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var int * * @ORM\ManyToOne(targetEntity="Canal",cascade={"persist"}) * @ORM\JoinColumn(name="canal_id", referencedColumnName="id", nullable=false) * @Assert\Valid */ private $canalId; /** * @ORM\ManyToMany(targetEntity="Client", cascade={"persist"}) * @ORM\JoinTable(name="leads_client") * * @Assert\Valid * */ private $contacts;
Mon controlleur :
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 /** * ClientContact * * @ORM\Table(name="client") * @ORM\Entity(repositoryClass="BackBundle\Repository\ClientRepository") */ class Client { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * @var string * * @ORM\Column(name="nom", type="string", length=255) * @Assert\NotBlank(message = "client.nom.not_blank") */ private $nom; /** * @var string * * @ORM\Column(name="prenom", type="string", length=255) */ private $prenom; /** * @var string * * @ORM\Column(name="telephone1", type="string", length=255) * @Assert\NotBlank(message = "client.telephone.not_blank") */ private $telephone1; /** * @var string * * @ORM\Column(name="telephone2", type="string", length=255) */ private $telephone2; /** * @var string * * @ORM\Column(name="email", type="string", length=255) */ private $email; /** * @var int * * @ORM\ManyToOne(targetEntity="TypeRelation") * @ORM\JoinColumn(name="relationtype_id", referencedColumnName="id", nullable=false) */ private $relationtypeId; /** * @var int * * @ORM\ManyToOne(targetEntity="TypeProspect") * @ORM\JoinColumn(name="typeprospect_id", referencedColumnName="id", nullable=false) */ private $typeprospectId; /** * @var \DateTime * * @ORM\Column(name="date_create", type="datetimetz") */ private $dateCreate; }
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 /** * @Route("/new", name="newapport") */ public function newAction(Request $request) { $currentdate = new \DateTime('now'); //Date du jour $leads = new Leads(); $leadsRepository = $this->getDoctrine()->getManager()->getRepository("BackBundle:Leads"); $leadsLines = $leadsRepository->findLastNumberByDateOrdered($currentdate->format('ymd'), "DESC"); $nbSuivant = "0001"; if (count($leadsLines) > 0) { $nbSuivant = str_pad(substr($leadsLines[0]->getNumeroLeads(), 6) + 1, 4, "0", STR_PAD_LEFT); } $refNumeroLeadsNew = $currentdate->format('ymd') . $nbSuivant; $leads->setNumeroLeads($refNumeroLeadsNew); $client = new Client(); $leads->addLeadsClient($client); $CommentaireLeads = new CommentaireLeads(); $leads->setLeadsApporteurAssociations($CommentaireLeads); $statutapportRepository = $this->getDoctrine()->getManager()->getRepository("BackBundle:StatutLeads"); $statutapport = $statutapportRepository->find(1); $leads->setStatutId($statutapport); $em = $this->getDoctrine()->getManager(); $form = $this->createForm(LeadsType::class, $leads); $form->handleRequest($request); if ($form->isSubmitted()) { $leads = $form->getData(); if ($form->isValid()) { if ($form->get('save')->isClicked()) { $this->get('session')->getFlashBag()->add('notice', array('type' => 'error', 'title' => 'Erreur!', 'message' => 'SAVE')); } if ($form->get('sendToCRC')->isClicked()) { $this->get('session')->getFlashBag()->add('notice', array('type' => 'error', 'title' => 'Erreur!', 'message' => 'SEND TO CRC')); } $em->persist($leads); $em->flush(); $this->get('session')->getFlashBag()->add('notice', array('type' => 'success', 'title' => 'Fait!', 'message' => 'Formulaire OK!')); $this->redirectToRoute("suiviapports"); } else { $this->get('session')->getFlashBag()->add('notice', array('type' => 'error', 'title' => 'Erreur!', 'message' => 'Formulaire INVALIDE!')); } } return $this->render('BackBundle:Apport:detail.html.twig', array( 'form' => $form->createView(), 'action' => "add", )); }
Es-ce al bonne méthode pour enregistrer ? j'ai une erreur : "The class 'Doctrine\Common\Collections\ArrayCollection' was not found in the chain configured namespaces BackBundle\Entity, FOS\UserBundle\Model"
Merci
Partager