bml/form-theme-bundle

此组件允许在表单类型类中定义表单主题。

安装次数: 4,730

依赖关系: 0

建议者: 0

安全性: 0

星标: 1

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

2.0.0 2021-05-04 10:47 UTC

This package is auto-updated.

Last update: 2024-09-04 18:06:36 UTC


README

表单主题组件允许在 FormType 类中定义表单主题。

有合并请求实现了此功能,等待审查: symfony/symfony#23990

安装

  1. composer require bml/form-theme-bundle
  2. 如果你没有使用 symfony flex,请将 new Bml\FormThemeBundle\BmlFormThemeBundle() 添加到 AppKernel.php

使用

要定义表单类型主题,为表单定义 theme 选项。例如在类型类中

class YourType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
           ->add('field')
           [...]
    }
    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'theme' => 'app/form/my_type_theme.html.twig'
        ]);
    }
}

当你调用 createView() 在你的表单上时,此组件将在后台调用相当于 {% form_theme form 'app/form/my_type_theme.html.twig' %} 的操作。