我有一个带有日期字段的实体,我的问题是我想给用户一个月和年份离开字段的可能性是无效的。因此,我想在我的日期字段中完全删除约束验证
我该怎么做?
这是我的字段
->add('datefield', DateType::class, array(
'data' => new DateTime(),
'format' => 'dd MMMM yyyy',
'required' => false,
'placeholder' => array(
'month' => 'empty',
'year' => 'empty'
)
))
和我的实体
/**
* @var DateTime
*
* @ORMColumn(name="datefield", type="datetime", nullable=true)
*/
protected $datefield;
这是我的错误
This value is not valid. datefield SymfonyComponentValidatorConstraintViolation
Object(SymfonyComponentFormForm).children[datefield] = [year => null, month => null, day => 18]
Caused by: SymfonyComponentFormExceptionTransformationFailedException
Unable to reverse value for property path "datefield": The fields "year", "month" should not be empty
Caused by: SymfonyComponentFormExceptionTransformationFailedException
The fields "year", "month" should not be empty
您是否也尝试过这样的空值:
->add('datefield', DateType::class, array(
'data' => new DateTime(),
'format' => 'dd MMMM yyyy',
'required' => false,
'placeholder' => array(
'month' => null,
'year' => null,
),
))
我不确定这是否会解决问题。尝试。