请有人告诉我为什么会收到错误。
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”,“disabled”,“label”,“label_format”,“translation_domain”,“validation_groups”
此表单用于详细阅读培训课程。它使用Symfony生成表单。我为每个领域制作了单独的表格。我相信我可能有格式错误的形式和它们的属性但是我不确定这是错误的原因。
答案 0 :(得分:1)
你有一个多维数组,你必须声明一个关联数组,如下所示:
$SessionSubmitForm = $this->createFormBuilder($Details)
->add('save', SubmitType::class, array('label' => 'Save Changes')
)
->getForm();