无法访问自定义表单类型的属性
Can't access to attributes of a custom form type
我刚刚通过嵌入表单创建了与另一个表单 'TrainingsType' 相关的表单类型 'InformationsType' 和 'TeamsType' 的两个自定义子项:
培训类型:
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(form)}} 呈现培训表格时,一切正常。
但在我的例子中,我需要循环 form.team.members,因为它是一个带有添加和删除选项的集合类型表单,
但这里
the problém that i can't access to team attribute ({{form(form.team)}},
it doesnt exist !!
我尝试转储(表单),但我得到了这个没有任何团队属性的 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
}
任何帮助,任何解释!!
我想你想用的是
attribute(form, team)
见https://twig.symfony.com/doc/2.x/functions/attribute.html
编辑:
您的转储看起来像是 InformationsType 而不是 TrainingsType 的转储,您确定您使用的是正确的形式吗?
我刚刚通过嵌入表单创建了与另一个表单 'TrainingsType' 相关的表单类型 'InformationsType' 和 'TeamsType' 的两个自定义子项:
培训类型:
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(form)}} 呈现培训表格时,一切正常。 但在我的例子中,我需要循环 form.team.members,因为它是一个带有添加和删除选项的集合类型表单, 但这里
the problém that i can't access to team attribute ({{form(form.team)}}, it doesnt exist !!
我尝试转储(表单),但我得到了这个没有任何团队属性的 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
}
任何帮助,任何解释!!
我想你想用的是
attribute(form, team)
见https://twig.symfony.com/doc/2.x/functions/attribute.html
编辑:
您的转储看起来像是 InformationsType 而不是 TrainingsType 的转储,您确定您使用的是正确的形式吗?