2017-02-15 107 views
0

請有人告訴我爲什麼出現錯誤。提交表單時出錯Symfony 2

public function trainingAction() 
{ 
    $em = $this->getDoctrine()->getManager(); 

    $Date = new AcademyTraining(); 
    $Date->setDate(new \DateTime('tomorrow')); 
    $Time = new AcademyTraining(); 
    $Time->setTime(); 
    $Topics = new AcademyTraining(); 
    $Topics->setTopics(''); 
    $Leader = new AcademyTraining(); 
    $Leader->setLeader(''); 
    $Details = new AcademyTraining(); 

    $Dateform = $this->createFormBuilder($Date) 
     ->add('date', DateType::class, array(
      'label' => false, 
      ) 
     ) 
     ->getForm(); 

    $Timeform = $this->createFormBuilder($Time) 
     ->add('time', TimeType::class, array(
      'input' => 'datetime', 

      'label' => false, 
      ) 
     ) 
     ->getForm(); 

    $Topicsform = $this->createFormBuilder($Topics) 
     ->add('Topics', TextType::class, array(
      'label' => false, 
      ) 
     ) 
     ->getForm(); 

    $Leaderform = $this->createFormBuilder($Leader) 
     ->add('Leader', ChoiceType::class, array(
      'choices' => array(
       'name' => 'Name', 
       'name2' => 'Name 2' 
      ), 
      'label' => false, 
      ) 
     ) 
     ->getForm(); 


    $SessionSubmitForm = $this->createFormBuilder($Details) 
     ->add('save', SubmitType::class, array(array('label' => 'Save Changes')) 
     ) 
     ->getForm(); 

    $user = $this->get('security.token_storage')->getToken()->getUser(); 
    $applicantstatus = $user->getApplicantStatus(); 



    if ($SessionSubmitForm->isSubmitted() && $SessionSubmitForm->isValid()) { 

     $Details = $Leaderform->getData(); 
     $Details = $Dateform->getData(); 
     $Details = $Timeform->getData(); 
     $Details = $Topicsform->getData(); 

     $em = $this->getDoctrine()->getManager(); 
     $em->persist($Details); 
     $em->flush(); 

     return $this->redirectToRoute('task_success'); 
    } 

    return $this->render('AppBundle:Academy/Applicants:trainingPTSpage.html.twig', array(
     'Timeform' => $Timeform->createView(), 
     'Topicsform' => $Topicsform->createView(), 
     'Dateform' => $Dateform->createView(), 
     'Leaderform' => $Leaderform->createView(), 
     'officers' => $em->getRepository('AppBundle:TrainingParticipants')->findAll(), 
     'session' => $em->getRepository('AppBundle:AcademyTraining')->findAll(), 
     "applicantstatus" => $applicantstatus 

    )); 

} 

的錯誤是:

選項 「0」 不存在。定義選項是:

這種形式被用在細節閱讀 「ATTR」, 「auto_initialize」, 「block_name」, 「已禁用」, 「標籤」, 「label_format」, 「translation_domain」, 「validation_groups」培訓課程。它使用Symfony生成表單。我爲每個領域製作了單獨的表格。我相信我可能格式錯誤的形式和他們的屬性,但我不知道這是錯誤的原因。

回答

1

你有一個多維數組,你必須聲明一個關聯數組,像這樣:

$SessionSubmitForm = $this->createFormBuilder($Details) 
    ->add('save', SubmitType::class, array('label' => 'Save Changes') 
    ) 
    ->getForm(); 
+0

這工作的感謝! – UnknownPerson

+0

不客氣,然後標記我的答案是正確的。 – panche14