2016-07-04 6 views
1

私はsymfonyでフォームで作業しています。選択したものでは、デフォルトでいくつかのオプションを選択したいと思っています。symfony defautによってさまざまなオプションを選択してください

私が試してきました:

$ gはのような配列である
->add('idgroupe', 
     ChoiceType::class, 
     array('label' => 'Groupes', 
      'attr' => array('expanded'=> false, 
          'data'=>$g, 
          'multiple'=>'true', 
          'class' => 'form-control' 
          ), 
      'choices' => $groupes 
      ) 
    ) 

array(1) { [0]=> string(18) "Vue1",[1]=> string(18) "Vue2" } 

しかし、私はこのエラーを持っている:

An exception has been thrown during the rendering of a template ("Notice: Array to string conversion")

+2

'expanded'、' multiple'と 'data'はoptions配列の' attr'部分にあるのではなく、 'attr'自身と同じレベルにあるべきです。 '' true '!== true'(引用符を削除する)。 – Yoshi

答えて

0

はして試してみてください。

->add('idgroupe', 
     ChoiceType::class, 
     array('label' => 'Groupes', 
      'attr' => array('class' => 'form-control' 
          ), 
      'expanded'=> false, 
      'data'=>$g, 
      'multiple'=>true, 
      'choices' => $groupes 
      ) 
    ); 
+3

Symfony> = 2.7を使用する場合は、オプション 'choices_as_values' => trueを設定してください。 http://symfony.com/blog/new-in-symfony-2-7-choice-form-type-refactorization – Elyass

+0

私は自分のフォームで間違いを犯しましたが、あなたのソリューションは機能します。ありがとう – kimpa2007

+0

こんにちは@ kimpa2007あなたのために良い見て、私の答えを受け入れること自由に感じて、ありがとう – Matteo

関連する問題