13

私は 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' のどちらを使用する必要があるかわかりません

4

3 に答える 3

8

試す:

->add('category', 'entity', array(
        'class'    => 'Acme\Entity\Category',
)

これは、エンティティがある場合にのみ機能しますCategory

SonataAdminBundleのエンティティのツリー エディターの作成については、この記事を参照してください。これはロシア語の同じ記事ですが、最初の亜種には欠落したコードが含まれていますCategory

于 2013-08-28T10:38:58.610 に答える