symfony 2 - “错误选项”0“不存在。”

时间:2017-03-01 12:33:32

标签: symfony entity formbuilder

我正在使用a2lix / TranslationFormBundle,我试图添加一个EntityType fiedl。

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

 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"

这是我的FormType

 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中使用它时,它不会。

任何帮助将不胜感激

1 个答案:

答案 0 :(得分: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',
            ] 
        ]
    ])