EntityType Symfony设置为默认值null [英] EntityType Symfony set default as null

查看:74
本文介绍了EntityType Symfony设置为默认值null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想如何使EntityType的第一个选项为NULL.

I would like how could a make that my first option of an EntityType is NULL.

我已经尝试过使用占位符,但是不可能,因为当我尝试注册表单时,它有义务选择一个不同于占位符的选项.

I've tried with a placeholder, but is not possible because when I try to register the form it obligate to select a different option which is not the place holder.

我正在尝试这样的事情:

I'm trying something like this:

->add('idacademicprogram', EntityType::class, array(
            "class" => 'AppBundle:Academicprogram',
            'placeholder' => 'Choose an option',
            "attr"=>array(
                "class" => "form-iduser form-control",
                "required" => false
            )))

推荐答案

好吧,我修复了对全局数组而不是attr进行更改的问题.

Ok i fixed changing required on global array, not on attr.

会是这样的:

->add('idacademicprogram', EntityType::class, array(
            "class" => 'AppBundle:Academicprogram',
            'placeholder' => 'Choose an option',
            'required' => false,
            "attr"=>array(
                "class" => "form-iduser form-control"
            )))

这篇关于EntityType Symfony设置为默认值null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆