【问题标题】:How to make sub groups in sonata admin form如何在奏鸣曲管理表单中创建子组
【发布时间】:2015-09-20 00:23:21
【问题描述】:

在索纳塔的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.

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

【问题讨论】:

    标签: symfony sonata-admin sonata


    【解决方案1】:

    如果你想使用标签,你的所有元素都必须在标签之间。

    在您的示例中,您在第一个 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();
    

    我用->tab('')代替->with('', array('tab' => true),更有意义。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-23
      • 1970-01-01
      • 2017-06-03
      • 1970-01-01
      • 2018-04-26
      • 1970-01-01
      • 2018-04-30
      相关资源
      最近更新 更多