I've problem with Collectiontype in Symfony 4.I try to save some informations in many table on database.My saving cascade is: 1 releve contains 1 carriere contains lots of infoCarriere contains lots of pointsTo save this information, i use a specific form with collectionType:My CarriereRelaiType:
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add("caisses", CollectionType::class, ['entry_type' => CarriereType::class,'allow_add' => true,'allow_delete' => true,'attr' => ['class' => 'col-sm-2'] ]); } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['data_class' => null,'empty_data' => null ]); }
My InfoCarriereRelaiType:
public function buildForm(FormBuilderInterface $builder, array $options) { $builder ->add("infoCarrieres", CollectionType::class, ['entry_type' => InfoCarriere::class,'allow_add' => true,'allow_delete' => true,'attr' => ['class' => 'col-sm-2'] ]); } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(['data_class' => null,'empty_data' => null ]); }
and i've the same for points.Show a part of my controller:
// creation carriere$recupCaisse = []; foreach ($dispatch as $keyDispatch => $valueDispatch){ if ($keyDispatch != "dateDoc"){ $recupCaisse[][$keyDispatch] = $valueDispatch; } } $compteurCaisse = count($recupCaisse); for ($i=0; $i<$compteurCaisse; $i++){ // creation de Carriere $dataCarriere["caisses"][$i] = new Carriere(); foreach ($recupCaisse[$i] as $keyCaisse => $valueCaisse){ // recuperation des noms de caisse $caisse = $caisseRepository->findByAcronyme(strtoupper($keyCaisse)); } $dataCarriere["caisses"][$i]->setCaisse($caisse[0]); // recuperation des numeros foreach ($valueCaisse as $keyDetail => $valueDetail) { if ($keyDetail == "numero") { $dataCarriere["caisses"][$i]->setNumero($valueDetail); } } } dump($dataCarriere); $formCarriere = $this->createForm(CarriereRelaiType::class, $dataCarriere); $formCarriere→handleRequest($request);for ($i=0; $i<$compteurCaisse; $i++){ foreach ($recupCaisse[$i] as $keyDetail => $valueDetail){ // ajout infocarriere foreach ($valueDetail as $keyTempInfoCarriere => $valueTempoInfoCarriere){ $dataInfoCarriere[$keyDetail][$keyTempInfoCarriere] = new InfoCarriere(); if (is_array($valueTempoInfoCarriere)){ foreach ($valueTempoInfoCarriere as $key => $value){ if ($key != "numeroDossier"){ if ($key == 'annee'){ $dataInfoCarriere[$keyDetail][$keyTempInfoCarriere]->setAnnee($value); }elseif ($key == 'debut'){ $dataInfoCarriere[$keyDetail][$keyTempInfoCarriere]->setDebut($value); }elseif ($key == 'fin'){ $dataInfoCarriere[$keyDetail][$keyTempInfoCarriere]->setFin($value); }elseif ($key == 'naturePeriode'){ $dataInfoCarriere[$keyDetail][$keyTempInfoCarriere]->setStatus($value); } } } } } } }dump($dataInfoCarriere);$formInfoCarriere = $this->createForm(InfoCarriereRelaiType::class, $dataInfoCarriere);$formInfoCarriere->handleRequest($request);
To show on my form with twig and save Carriere is ok.I want to show all my form with all informations but i've this error message:
Could not load type "App\Entity\InfoCarriere": class does not implement "Symfony\Component\Form\FormTypeInterface".
On my dump ($dataCarriere & $dataInfoCarriere), i have the same structure but, in the $dataCarriere i have juste 1 entry:
array:1 [▼"caisses" => array:4 [▼ 0 => App\Entity\Carriere {#1154 ▶} 1 => App\Entity\Carriere {#1801 ▶} 2 => App\Entity\Carriere {#1860 ▶} 3 => App\Entity\Carriere {#1891 ▶} ]]
and in the $dataInfoCarriere i have 4 entries:
array:4 [▼"truc" => array:35 [▶]"bidule" => array:14 [▶]"machin" => array:8 [▶]"chose" => array:23 [▶]]
(a part of 1 entry)
array:4 [▼"truc" => array:35 [▼ 11 => App\Entity\InfoCarriere {#1943 ▶} 12 => App\Entity\InfoCarriere {#2090 ▶} 13 => App\Entity\InfoCarriere {#2105 ▶} 14 => App\Entity\InfoCarriere {#2107 ▶} 15 => App\Entity\InfoCarriere {#2326 ▶} 16 => App\Entity\InfoCarriere {#2398 ▶} 17 => App\Entity\InfoCarriere {#2401 ▶} 18 => App\Entity\InfoCarriere {#2403 ▶}
I tried to change my $dataInfoCarriere entry with just one, but the same error message.I think i forgot something but i don't know what.thank you in advance for your help