Symfony 3.4 - Sonata - 实体字段作为日期 - 问题

Symfony 3.4 - Sonata - Entity field as Date - Problems

我有一个实体。 我将字段创建为 Datetime 格式

/**
 * @var \DateTime
 *
 * @ORM\Column(name="date", type="datetime", nullable=true, unique=false)
 */
private $date;

执行架构更新后数据库中的字段正常。

这是在 Sonata 上使用的映射,并且正确显示:

->add('date', 'sonata_type_datetime_picker', [
        'label' => 'admin.entity.community.fields.date.label',
        'required' => true,
        'format' => 'dd/MM/Y',
        'dp_pick_time' => false,
        'dp_use_current' => true,
    ])

Select 2018 年 1 月 7 日在球场上。救球 在数据库中保存值:2017-12-25 00:00:00.000000

preUpdate 我追踪了这个领域。跟踪结果:

object(DateTime)#950 (3) { ["date"]=> string(26) "2017-12-25 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Madrid" }

您可以编辑:

->add('date','sonata_type_date_picker',array('label' => 'Date','widget' => 'single_text','format' => 'yyyy-MM-dd',))

@documentation Sonata-Admin 捆绑包:https://sonata-project.org/bundles/core/master/doc/reference/form_types.html