如何设置最小值 DateTimeType [Symfony]
How to set min value DateTimeType [Symfony]
我想在输入日期中设置最小日期
$builder->add('dateRdv', DateTimeType::class,['data' => new \DateTime(),
'attr' => ['min' => new \DateTime()]])
错误是:
An exception has been thrown during the rendering of a template
("Catchable Fatal Error: Object of class DateTime could not be
converted to string").
**
您正在使用 Datetime 作为字符串,如错误所述,只需将其格式化为字符串即可:
$builder->add('dateRdv', DateTimeType::class,['data' => new \DateTime(),
'attr' => ['min' => ( new \DateTime() )->format('Y-m-d H:i:s')]]);
我想在输入日期中设置最小日期
$builder->add('dateRdv', DateTimeType::class,['data' => new \DateTime(),
'attr' => ['min' => new \DateTime()]])
错误是:
An exception has been thrown during the rendering of a template ("Catchable Fatal Error: Object of class DateTime could not be converted to string").
**
您正在使用 Datetime 作为字符串,如错误所述,只需将其格式化为字符串即可:
$builder->add('dateRdv', DateTimeType::class,['data' => new \DateTime(),
'attr' => ['min' => ( new \DateTime() )->format('Y-m-d H:i:s')]]);