我正在使用Sonata Admin并且我有一个类别的字段,我需要像select中的树一样按顺序显示它们:
<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>
Run Code Online (Sandbox Code Playgroud)
这是可能的?我试过它在'choice_list'中包含一个getTreeCatsArray方法中的数组生成:
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));
}
Run Code Online (Sandbox Code Playgroud)
这显示错误:
The option "choice_list" with value "Array" is expected to be of type "null", "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface"
Run Code Online (Sandbox Code Playgroud)
我不确定是否必须使用字段类型'sonata_type_model'或'choice'