我正在使用symfony形式工作,並在選擇中選擇我想要的選項。Symfony通過defaut選擇各種選項
我已經嘗試:
->add('idgroupe',
ChoiceType::class,
array('label' => 'Groupes',
'attr' => array('expanded'=> false,
'data'=>$g,
'multiple'=>'true',
'class' => 'form-control'
),
'choices' => $groupes
)
)
其中$ g是一個數組,如:
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")
'expanded','multiple'和'data'不應該放在options-array的'attr'部分,而應該放在與'attr'本身相同的層上。也是'「true」!== true'(刪除引號)。 – Yoshi