adamquaile / symfony-fieldset-bundle
在 Symfony 表单中添加 Fieldset 类型
v1.1.3
2017-05-24 13:16 UTC
Requires
- php: >=5.3.3
Requires (Dev)
- symfony/config: ~2.5.0
- symfony/dependency-injection: ~2.5.0
- symfony/form: ~2.5.0
- symfony/http-kernel: ~2.5.0
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' ] ] ] ]);