小编Raú*_*aúl的帖子

使用Sonata Admin自定义选择sonata_type_model字段列表

我正在使用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'

symfony sonata-admin

13
推荐指数
2
解决办法
3万
查看次数

标签 统计

sonata-admin ×1

symfony ×1