2017-07-26 67 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