adamquaile/symfony-fieldset-bundle

在 Symfony 表单中添加 Fieldset 类型

安装次数: 40,811

依赖关系: 0

建议者: 0

安全: 0

星星: 17

关注者: 3

分支: 11

开放问题: 8

类型:symfony-bundle

v1.1.3 2017-05-24 13:16 UTC

This package is auto-updated.

Last update: 2024-09-05 23:43:02 UTC


README

为 Symfony 项目添加 Fieldset 类型。

安装

通过 composer 从 adamquaile/symfony-fieldset-bundle 安装。

app/AppKernel.php 中注册

public function registerBundles()
{
    $bundles = array(
        // ...
        new AdamQuaile\Bundle\FieldsetBundle\AdamQuaileFieldsetBundle(),
    );

    //...
}

用法

使用常规表单构建方法

// A fieldset with your fields defined in a callback function
$builder->add('my_group_example_one', FieldsetType::class, [
    'label' => false, // You probably don't want a label as well as a legend.
    'legend' => 'Your fieldset legend',
    'fields' => function(FormBuilderInterface $builder) {
        $builder->add('first_name', TextType::class, [
            'label' => 'First Name'
        ]);
        $builder->add('last_name', TextType::class, [
            'required'  => false,
            'label'     => 'Surname'
        ]);
    }
]);

// A fieldset with your fields defined in an array
$builder->add('my_group_example_two', FieldsetType::class, [
    'label' => false,
    'legend' => 'Your fieldset legend',
    'fields' => [
        [
            'name'  => 'first_name',
            'type'  => TextType::class,
            'attr'  => [
                'label' => 'First Name'
            ]
        ],
        [
            'name'  => 'last_name',
            'type'  => TextType::class,
            'attr'  => [
                'required'  => false,
                'label'     => 'Surname'
            ]
        ]
    ]
]);