簡體   English   中英

Symfony2日期驗證失敗

[英]Symfony2 date validation fails

我有一個看起來像這樣的表單類型:

/**
 * {@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.dev/user/profile

{ 
    "user_profile" : { 
        "sex" : 0,
        "birthdate" : {
            "year"  : 1983,
            "month" : 6,
            "day"   : 23
        },
        "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" : "2014-01-01",
        "height" : 180,
        "weight" : 78,
        "pal"    : 1.2
    }
}

我做錯了什么? 請幫助:'(

更新:

如果我使用widget => single_text ,則在添加表單字段時,我可以成功地請求這個端點的birthdate1974-05-06 ,但是我希望能夠發送更多的僅一種格式:

  • 日期時間對象
  • 時間戳記
  • YYYY-MM-DD
  • 數組

更新2如果我使用小部件=>文本,我可以按預期方式發送三個子表單字段。 但是我不能將這些值作為字符串發送。

不過...。我將關閉它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM