Doctrine 2.1 - datetime列的默认值 [英] Doctrine 2.1 - datetime column default value
本文介绍了Doctrine 2.1 - datetime列的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected $ registration_date = date(Ymd H:i:s,time ));
那么如何?
解决方案
将属性映射为DateTime类型,然后使用新的DateTime实例在构造函数中设置值:
/ **
* @Entity
* @Table(name =...)
* /
class MyEntity
{
/ * * @Column(type =datetime)* /
protected $ registration_date;
public function __construct()
{
$ this-> registration_date = new DateTime();
}
}
这作为持久化类的构造函数不是要求水合。
Could someone tell me how to add default value on datetime column? I can't do this like this:
protected $registration_date = date("Y-m-d H:i:s", time());
So how?
解决方案
You map your property as DateTime type then set the value in the constructor using a new DateTime instance:
/**
* @Entity
* @Table(name="...")
*/
class MyEntity
{
/** @Column(type="datetime") */
protected $registration_date;
public function __construct()
{
$this->registration_date = new DateTime();
}
}
This works as the constructor of a persisted class is not called upon hydration.
这篇关于Doctrine 2.1 - datetime列的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文