Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Symfony 如何在sonata管理表单中创建子组_Symfony_Sonata Admin_Sonata - Fatal编程技术网

Symfony 如何在sonata管理表单中创建子组

Symfony 如何在sonata管理表单中创建子组,symfony,sonata-admin,sonata,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 *

在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();
     *
     */
不幸的是,如果我先添加一个组,然后再添加选项卡,就会出现错误。我希望我的表单有一个主要的简单表单(firstname等),然后在它下面的选项卡上逐个选项卡列出实体关系表单(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之间缺少一个选项卡,您应该执行以下操作:

$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();
与(“”,array('tab'=>true)相比,我使用了
->tab(“”)
,这更有意义

此外,也不再支持折叠:

文件: