2
我想在Symfony的3 建立一個複選框列表此代碼:Symfony的3怪異的「選擇」的錯誤
$choices = [
'a' => 'fsssssss',
];
$builder->add('memberships', ChoiceType::class, [
'choices' => $choices,
'expanded' => true,
'multiple' => false
]);
返回以下錯誤:捕致命錯誤:類學說的對象\ ORM \ PersistentCollection無法轉換爲vendor/symfony/symfony/src/Symfony/Component/Form/ChoiceList/ArrayChoiceList.php中的字符串(行73)
如果我添加兩個選項,錯誤消失,字段顯示正確:
$choices = [
'a' => 'fsssssss',
'd' => 'fsssssss',
'g' => 'fsssssss',
];
$builder->add('memberships', ChoiceType::class, [
'choices' => $choices,
'expanded' => true,
'multiple' => false
]);
其實,有很多組合工作,許多不這樣做;我沒有看到任何模式。
我做錯了什麼?是否有某種緩存需要清除?
嘗試將其添加到下面的''multiple'=> false':''choice_label'=>函數($ value,$ key,$ index){ return $ key; },' –
它沒有幫助:( – user3429660
fsssssss是關鍵,而不是你的選擇的價值,你需要改變它 –