0

我在我的 Symfony 项目中有一个实体,其字段“brand”可以为 null找出问题所在。

实体:

/**
 * @var string
 *
 * @ORM\Column(name="brand", type="string", length=255, nullable=false)
 */
private $brand;

表格:

    ->add('translations', 'a2lix_translations', array(
                'fields' => array(
                    'brand' => array(
                        'field_type' => TextType::class,
                        'required'   => true
                    ),
                )
            )
        )`

我也试过这个,但前面仍然没有出现:

    ->add('translations', 'a2lix_translations', array(
                'fields' => array(
                    'brand' => array(
                        'field_type' => TextType::class,
                        'locale_options' => array(            
                              'en' => array(
                                'required' => true
                             ),
                              'fr' => array(
                                'required' => true
                            )
                        )
                    ),
                )
            )
        )`

在浏览器中这两种情况的结果是:

<input type="text" id="video_form_translations_en_brand" name="video_form[translations][en][brand]" maxlength="255" class="form-control">
4

1 回答 1

0

我刚刚更正了在我的 config.yml 中将两种语言设置为所需语言环境的问题。现在,我必需的真实字段具有必需的属性,非必需字段仍然是非必需的。

# A2lix Configuration
a2lix_translation_form:
    locale_provider: default
    locales: "%languages%"          # locales available for the forms
    default_locale: "%locale%"      # default locale
    required_locales: [en, fr]         # requireds locales (not all fields will be required - only the ones with required true)
    manager_registry: doctrine
    templating: "A2lixTranslationFormBundle::default.html.twig"
于 2016-05-17T10:50:54.370 回答