[英]Symfony FOSREST API Datetime Error
I'm using symfony 2.7, I have created the API, When I submit the form(json data) using postman, It is not accepting datetime value. 我正在使用symfony 2.7,我创建了API,当我使用邮递员提交表单(json数据)时,它不接受datetime值。
Form Builder 表单生成器
->add('letAt','datetime')
Command 命令
/**
* @var DateTime
* @Assert\NotNull(message="Please enter let at time.")
*/
protected $letAt;
Entity 实体
/**
* @var \DateTime
* @ORM\Column(type="datetime", nullable=true)
*/
protected $letAt;
Request Json 请求杰森
{
"property_type":
{
"marketingTitle": "",
"letAt": "2018-11-11 10:10:10"
}
}
Error 错误
"errors": {
"children": {
"marketingTitle": {},
"letAt": {
"errors": [
"This value is not valid."
],
"children": {
"date": {
"children": {
"year": {},
"month": {},
"day": {}
}
},
"time": {
"children": {
"hour": {},
"minute": {}
}
}
}
},
How can I specify dateTime value with Request? 如何使用Request指定dateTime值?
In Symfony 2.7 the default datetime
format is \\DateTimeType::HTML5_FORMAT
and it's value yyyy-MM-dd'T'HH:mm:ssZZZZZ
. 在Symfony 2.7中,默认
datetime
格式为\\DateTimeType::HTML5_FORMAT
,其值为yyyy-MM-dd'T'HH:mm:ssZZZZZ
。
You specify your format type like that: 您可以这样指定格式类型:
->add('letAt','datetime', array('format' => 'yyyy-MM-dd HH:mm:ss', 'widget' => 'single_text'))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.