如何设置最小值 DateTimeType [Symfony] [英] How to set min value DateTimeType [Symfony]
本文介绍了如何设置最小值 DateTimeType [Symfony]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在输入日期中设置最小日期
I want to set the minimal date in input date
$builder->add('dateRdv', DateTimeType::class,['data' => new \DateTime(),
'attr' => ['min' => new \DateTime()]])
错误是:
模板渲染过程中抛出异常(可捕获的致命错误: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 作为字符串,正如错误所说,只需将其格式化为字符串:
You are using Datetime as a string, as the error said, just format it into a string:
$builder->add('dateRdv', DateTimeType::class,['data' => new \DateTime(),
'attr' => ['min' => ( new \DateTime() )->format('Y-m-d H:i:s')]]);
这篇关于如何设置最小值 DateTimeType [Symfony]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文