gpt4 book ai didi

symfony - 如何在奏鸣曲管理表单中创建子组

转载 作者:行者123 更新时间:2023-12-02 18:36:42 27 4
gpt4 key购买 nike

在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.

有人知道如何实现这个功能吗?或者这是两个独立的例子?如果可能的话,我希望避免使用纯选项卡,因此无法使我的表单的一部分始终可见。

最佳答案

如果您想使用选项卡,则所有元素都必须位于选项卡之间。

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

关于symfony - 如何在奏鸣曲管理表单中创建子组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31185136/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com