如何在奏鸣曲管理表格中制作子组

时间:2015-07-02 12:48:32

标签: symfony sonata-admin sonata

在Sonata的AdminBundle\Mapper\BaseGroupedMapper.php中,我看到了一个代码示例:

    public function with($name, array $options = array())
    {
    /*
     * The current implementation should work with the following workflow:
     *
     *     $formMapper
     *        ->with('group1')
     *            ->add('username')
     *            ->add('password')
     *        ->end()
     *        ->with('tab1', array('tab' => true))
     *            ->with('group1')
     *                ->add('username')
     *                ->add('password')
     *            ->end()
     *            ->with('group2', array('collapsed' => true))
     *                ->add('enabled')
     *                ->add('createdAt')
     *            ->end()
     *        ->end();
     *
     */

不幸的是,如果我先添加一个组然后添加标签,我会收到错误消息。我希望我的表单有一个主要的简单形式(名字等等),然后在它下面的选项卡列出实体关系表单(onetomany ...)选项卡,以保持它清洁。不幸的是,我收到了这个错误:

New tab was added automatically when you have added field or group. You should close current tab before adding new one OR add tabs before adding groups and fields.

有谁知道如何使这项工作?或者这是两个分开的例子?我希望尽可能避免使用纯粹的标签,因此无法使我的表单的一部分始终可见。

1 个答案:

答案 0 :(得分:3)

如果要使用制表符,则所有元素必须位于制表符之间。

在您的示例中,您缺少第一个group1之间的标签,您应该这样做:

$formMapper
    ->tab('General')
        ->with('group1')
            ->add('username')
            ->add('password')
        ->end()
    ->end()
    ->tab('Relations')
        ->with('group1')
            ->add('username')
            ->add('password')
        ->end()
        ->with('group2')
            ->add('enabled')
            ->add('createdAt')
        ->end()
    ->end();

而不是使用->with('', array('tab' => true)我使用->tab(''),更有意义。

不再支持折叠:https://stackoverflow.com/a/29105992/3726645

文档:https://sonata-project.org/bundles/admin/master/doc/reference/action_create_edit.html#formgroup-options

相关问题