【问题标题】:symfony 2 - “error The option ”0“ does not exist.”symfony 2 - “错误选项“0”不存在。”
【发布时间】:2017-03-01 12:33:32
【问题描述】:

我正在使用 a2lix/TranslationFormBundle 并尝试添加一个 EntityType 字段。

当我尝试构建表单时出现此错误:

 The option "0" does not exist. Known options are: "action", "attr", "auto_initialize", "block_name", "by_reference", "compound", "csrf_field_name", "csrf_message", "csrf_protection", "csrf_provider", "csrf_token_id", "csrf_token_manager", "data", "data_class", "disabled", "empty_data", "error_bubbling", "inherit_data", "intention", "label", "label_attr", "label_format", "mapped", "max_length", "method", "pattern", "post_max_size_message", "property_path", "read_only", "required", "translation_domain", "trim", "virtual"

这是我的表单类型

 use Symfony\Bridge\Doctrine\Form\Type\EntityType;
 use A2lix\TranslationFormBundle\Form\Type\TranslationsType;

public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
        ->add('tag', TextType::class)
        ->add('translations', TranslationsType::class, [
            'fields' => [
                'promotion' => ['field_type' => EntityType::class, [
                    'class' => 'AdminBundle:Promotion',
                    'choice_label' => 'getName'
                ] ]
            ]
        ])
        ->add('Save', SubmitType::class)
    ;
}

当我在 TranslationType 字段之外使用 EntityType 字段时,它可以正常工作。但是当我在 TranslationType 中使用它时,它不会。

任何帮助将不胜感激

【问题讨论】:

    标签: symfony entity formbuilder


    【解决方案1】:

    我在尝试自定义 A2lix 表单中的 CKEditor 工具栏时遇到了类似的错误。

    解决方案不容易找到。而不是像这样为您正在集成的类的选项添加新数组:

     $builder
        ->add('tag', TextType::class)
        ->add('translations', TranslationsType::class, [
            'fields' => [
                'promotion' => ['field_type' => EntityType::class, [
                    'class' => 'AdminBundle:Promotion',
                    'choice_label' => 'getName'
                ] ]
            ]
        ])
    

    你应该尝试这样写(即直接将选项放入数组中用于“促销”):

      $builder
        ->add('tag', TextType::class)
        ->add('translations', TranslationsType::class, [
            'fields' => [
                'promotion' => ['field_type' => EntityType::class, 
                    'class' => 'AdminBundle:Promotion',
                    'choice_label' => 'getName',
                ] 
            ]
        ])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-25
      • 2015-07-25
      相关资源
      最近更新 更多