奏鸣曲日期选择器月份重置为1

时间:2017-02-13 01:21:46

标签: symfony jquery-ui-datepicker symfony-forms sonata-admin

我使用sonata_type_datetime_range_picker。我在前端工作正确。但是当我提交表单时,它会将月份值重新设置为1。我提交的值是“2017-02-02 03:14:00”,提交后的值是“2017-01-02 03:14:00”。根据分析器日期在Request对象中是正确的,但在Symfont Form Component中是错误的。

我的管理员代码

    $datePickerOptions = [
        'format' => "YYYY-MM-DD HH:mm:SS",
        'datepicker_use_button' => false,
        'dp_use_minutes' => false,
        'dp_use_seconds' => false,
        'dp_side_by_side' => true,
        'dp_language' => 'en',
    ];

    $datagridMapper
        ->add(
            'dateTime',
            'doctrine_orm_datetime_range',
            [
                'show_filter' => true,
                'field_type' => 'sonata_type_datetime_range_picker',
                'field_options' => [
                    'field_options_start' => $datePickerOptions,
                    'field_options_end' => $datePickerOptions,
                ],
            ]
        );

我做错了什么?

1 个答案:

答案 0 :(得分:0)

好的,我有点找到了自己的工作方案。也许它有时会帮助其他人:

    $now  = new \DateTime();
    $historyStart = new \DateTime('Dec 20 2016');
    $dateFormat = 'd.m.y H';

    $datagridMapper
        ->add(
            'dateTime',
            'doctrine_orm_datetime_range',
            ['show_filter' => true,],
            'sonata_type_datetime_range_picker',
            [
                'field_options_start' => [
                    'dp_min_date'     => $historyStart->format($dateFormat),
                    'dp_max_date'     => $now->format($dateFormat),
                    'dp_default_date' => $now->format($dateFormat),
                    'dp_language'     => 'en',
                    'format' => 'dd.MM.yy HH',
                    'datepicker_use_button' => false,
                    'dp_use_minutes' => false,
                    'dp_use_seconds' => false,
                    'dp_side_by_side' => true,
                ],
                'field_options_end' => [
                    'dp_min_date'     => $historyStart->format($dateFormat),
                    'dp_max_date'     => $now->format($dateFormat),
                    'dp_default_date' => $now->format($dateFormat),
                    'dp_language'     => 'en',
                    'format' => 'dd.MM.yy HH',
                    'datepicker_use_button' => false,
                    'dp_use_minutes' => false,
                    'dp_use_seconds' => false,
                    'dp_side_by_side' => true,
                ]
            ]
        );