【发布时间】:2016-03-24 14:40:15
【问题描述】:
我想在 Symfony 3 中循环添加自定义表单,例如:
$defaultData = array('message' => 'Type your message here');
$profilForm = $this->createFormBuilder($defaultData)
->add('Nom', TextType::class);
->add('Description', TextType::class)
foreach ($variable as $key => $value)
{
$profilForm
->add('Widget', ChoiceType::class, array(
'choices' => array(
'Créer' => 'C',
'Afficher' => 'R',
'Modifier' => 'U',
'Supprimer' => 'D'),
'multiple' => true,
'expanded' => true))
}
$profilForm
->add('send', SubmitType::class)
->getForm();
问题是我得到了错误:
试图调用“Symfony\Component\Form\FormBuilder”类的名为“createView”的未定义方法。
如果我这样做:
$defaultData = array('message' => 'Type your message here');
$profilForm = $this->createFormBuilder($defaultData)
->add('Nom', TextType::class);
->add('Description', TextType::class)
foreach ($variable as $key => $value)
{
$profilForm = $this->createFormBuilder($defaultData)
->add('Widget', ChoiceType::class, array(
'choices' => array(
'Créer' => 'C',
'Afficher' => 'R',
'Modifier' => 'U',
'Supprimer' => 'D'),
'multiple' => true,
'expanded' => true))
}
$profilForm
->add('send', SubmitType::class)
->getForm();
它会覆盖以前的条目。
【问题讨论】: