我有以下 Doctrine2 实体:
<?php
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Timestampable\Traits\TimestampableEntity;
/**
* @ORM\Entity
*/
class Account
{
use TimestampableEntity;
/**
* @var integer
*
* @ORM\Id
* @ORM\Column(type="integer", unique=true, nullable=false)
*/
private $id;
}
正如你所看到的,我正在使用Gedmo 时间戳 https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/timestampable.md与Trait https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/timestampable.md#traits由捆绑包提供。运行良好。
当我获取数据和列时出现问题updated_at
即将到来NULL
罢工>0000-00-00 00:00:00
。对于这种情况DateTime
对象被翻译成invalid日期如下图所示:
array (
'RowId' => 26944,
'synchflag' => 1,
'updatedAt' =>
DateTime::__set_state(array(
'date' => '-0001-11-30 00:00:00.000000',
'timezone_type' => 3,
'timezone' => 'UTC',
)),
)
我确实检查过docs http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/cookbook/working-with-datetime.html但没有任何帮助(或者至少我没有找到它,如果你让我知道的话)
处理这个问题的正确方法是什么?
EDIT:
也许这里正确的问题应该是:如果updated_at
即将到来0000-00-00 00:00:00
我怎样才能把它变成NOW()
?正如您可能注意到的getUpdatedAt()
返回一个DateTime
基于获取的数据。有什么活动吗SELECT
陈述?