2017-07-26 147 views
0

我刚刚创建定制的拖车的形式输入“InformationsType”,并通过嵌入形式与另一种形式的“TrainingsType” 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); 
    } 

TeamsType:

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, 
      ]); 

    } 

InformationsType:

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,因为它与附加一个集合类型的表单和删除选项, 但这里

,我无法访问组队属性问题({{形式(form.team)}}, 它不存在!

我试图转储(形式)和我没有得到任何球队的FormView此对象的属性是有线的,因为我得到了我的形式,当我通过rendred {{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 
} 

任何帮助,任何解释!

+0

你能向我们展示控制器中的newAction()吗?我猜你正在使用错误的'FormType' – SlimenTN

回答

1

我想你想用的是

attribute(form, team) 

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

编辑:

转储看起来像InformationsType的转储,而不是TrainingsType,你确定你使用正确的形式?

+0

它引发一个异常:变量“team”不存在。 – ahmedbhs

+0

与信息属性 – ahmedbhs

+0

相同的例外您的转储看起来像InformationSType的转储而不是TrainingsType,您确定您使用的是正确的表单吗?你可以用你的控制器更新这个问题吗? – Strnm