私は Sonata Admin を使用しています。カテゴリのフィールドがあり、選択したツリーのように順番に表示する必要があります。
<select>
<option>Category father-1</option>
<option>--Category child-1-1</option>
<option>--Category child-1-2</option>
<option>--Category child-1-3</option>
<option>----Category child-1-3-1</option>
<option>----Category child-1-3-2</option>
<option>--Category child-1-4</option>
<option>--...</option>
<option>Category father-2</option>
</select>
それが可能だ?getTreeCatsArray メソッドで生成される配列を「choice_list」に含めてみました。
protected function configureFormFields(FormMapper $formMapper)
{
$tree_cat_array = $this->em->getRepository('MyBundle:Category')->getTreeCatsArray();
$formMapper
->add('category', 'sonata_type_model', array(
'empty_value' => '',
'choice_list' => $tree_cat_array));
}
これはエラーを示しています:
The option "choice_list" with value "Array" is expected to be of type "null", "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface"
フィールド タイプ 'sonata_type_model' または 'choice' のどちらを使用する必要があるかわかりません