Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date Symfony2日期验证失败_Date_Symfony_Validation - Fatal编程技术网

Date Symfony2日期验证失败

Date Symfony2日期验证失败,date,symfony,validation,Date,Symfony,Validation,我有一个表单类型,如下所示: /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('birthdate', 'date')); } 我的验证器: Foo\BarBundle\Model\User\Profile: properties: birthdate:

我有一个表单类型,如下所示:

/**
 * {@inheritdoc}
 */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder->add('birthdate', 'date'));
}
我的验证器:

Foo\BarBundle\Model\User\Profile:
    properties:
        birthdate:
            - NotNull:
                message : label.null
            - Date:
                message: user.profile.birthdate.invalid
带有请求正文数据的我的请求:

Foo\BarBundle\Model\User\Profile:
    properties:
        birthdate:
            - NotNull:
                message : label.null
            - Date:
                message: user.profile.birthdate.invalid
放置foo.dev/user/profile

{ 
    "user_profile" : { 
        "sex" : 0,
        "birthdate" : {
            "year"  : 1983,
            "month" : 6,
            "day"   : 23
        },
        "height" : 180,
        "weight" : 78,
        "pal"    : 1.2
    }
}
{ 
    "user_profile" : { 
        "sex" : 0,
        "birthdate" : "2014-01-01",
        "height" : 180,
        "weight" : 78,
        "pal"    : 1.2
    }
}
这给了我一个400:

{
    "code":400,
    "message":"Validation Failed",
    "errors":{
    "children":{
        "birthdate":{
            "errors":[
                "This value is not valid."
            ],
            "children":{
                "year":[],
                "month":[],
                "day":[]
            }
        },
    }
}
同样的情况也会发生,如果我使用这个:

放置foo.dev/user/profile

{ 
    "user_profile" : { 
        "sex" : 0,
        "birthdate" : {
            "year"  : 1983,
            "month" : 6,
            "day"   : 23
        },
        "height" : 180,
        "weight" : 78,
        "pal"    : 1.2
    }
}
{ 
    "user_profile" : { 
        "sex" : 0,
        "birthdate" : "2014-01-01",
        "height" : 180,
        "weight" : 78,
        "pal"    : 1.2
    }
}
我做错了什么?请帮忙:'(

更新:

Foo\BarBundle\Model\User\Profile:
    properties:
        birthdate:
            - NotNull:
                message : label.null
            - Date:
                message: user.profile.birthdate.invalid
如果我使用
widget
=>
single_text
,在添加表单字段时,我可以使用
出生日期成功请求此端点:
1974-05-06
,但我希望能够发送更多,而不仅仅是1种格式:

  • 日期时间对象
  • 时间戳
  • YYYY-MM-DD
  • 排列
更新2 如果我使用widget=>text,我可以按预期发送三个子表单字段,但我不能将这些值作为字符串发送

尽管如此,我还是会关闭此对话框。

我建议您使用。但我认为接受多种格式需要大量工作才能识别并解析每种格式。祝您好运!