我刚刚创建了两个表单类型为“InformationsType”和“TeamsType”的自定义子项,通过嵌入表单与另一个表单“TrainingsType”相关:
use AppBundle\Form\InformationsType;
use AppBundle\Form\TeamsType;
class TrainingsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('team', TeamsType::class)
->add('information', InformationsType::class);
}
团队类型:
class TeamsType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('nameInstitue')->add('nameSpace')->add('webSpace')
->add('members', CollectionType::class, [
'entry_type' => Team_membersType::class,
'allow_delete' => true,
'allow_add' => true,
'by_reference' => false,
]);
}
信息类型:
class InformationsType extends AbstractType
{
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('category', ChoiceType::class, array(
'choices' => array(
'Formation' => 'Francais',
'Certification' => 'Certification',
'Tutoriel' => 'Tutoriel',
'Conférence' => 'Conférence',
'Atelier' => 'Atelier',
'Webinar' => 'Webinar',
'Meet-up' => 'Meet-up',
),
))->add('language', ChoiceType::class, array(
'choices' => array(
'Francais' => 'Francais',
'Anglais' => 'Anglais',
),
))->add('eventType', ChoiceType::class, array(
'choices' => array(
'Permanant' => 'Permanant',
'Session' => 'Session',
),
))->add('priceDescription')->add('title')->add('webAdress')->add('description')->add('priceRadio')->add('validationType')
->add('trainingPrice',ChoiceType::class, array(
'choices' => array('Gratuit'=>'Gratuit','Payant'=>'Payant','Abonnement'=>'Abonnement'),'multiple'=>false,'expanded'=>true))
->add('isCheckedPiece', CheckboxType::class, array(
'required' => false,
));
}
但在我的情况下,我需要循环form.team。成员,因为它是具有添加和删除选项的集合类型表单,
但是在这里
我无法访问团队属性({form(form.team)}})的问题,
我试图转储(form),我得到了这个Formview对象,它没有任何连接的团队属性,因为我通过{form(form)}}进行渲染时得到了我的表单:
FormView {#365 â¼
+vars: array:24 [â¼
"value" => Informations {#313 â¶}
"attr" => []
"form" => FormView {#365}
"id" => "appbundle_informations"
"name" => "appbundle_informations"
"full_name" => "appbundle_informations"
"disabled" => false
"label" => null
"label_format" => null
"multipart" => false
"block_prefixes" => array:3 [â¶]
"unique_block_prefix" => "_appbundle_informations"
"translation_domain" => null
"cache_key" => "_appbundle_informations_appbundle_informations"
"errors" => FormErrorIterator {#555 â¶}
"valid" => true
"data" => Informations {#313 â¶}
"required" => true
"size" => null
"label_attr" => []
"compound" => true
"method" => "POST"
"action" => ""
"submitted" => false
]
+parent: null
+children: array:12 [â¼
"category" => FormView {#610 â¶}
"language" => FormView {#641 â¶}
"eventType" => FormView {#659 â¶}
"priceDescription" => FormView {#668 â¶}
"title" => FormView {#670 â¶}
"webAdress" => FormView {#672 â¶}
"description" => FormView {#674 â¶}
"priceRadio" => FormView {#676 â¶}
"validationType" => FormView {#678 â¶}
"trainingPrice" => FormView {#680 â¶}
"isCheckedPiece" => FormView {#682 â¶}
"_token" => FormView {#696 â¶}
]
-rendered: false
-methodRendered: false
}