代码之家  ›  专栏  ›  技术社区  ›  famas23

无法访问自定义表单类型的属性

  •  0
  • famas23  · 技术社区  · 9 年前

    我刚刚创建了两个表单类型为“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
    }
    

    1 回复  |  直到 9 年前
        1
  •  1
  •   Strnm    9 年前

    我想你想用的是

    attribute(form, team)
    

    https://twig.symfony.com/doc/2.x/functions/attribute.html

    推荐文章