2

我正在尝试使用以下代码在 mysql datetime 列中插入日期时间,但它没有被插入。而 isDelete 工作正常。

/*
 * 
 * @ORM\Column (type="datetime")
 */
protected $created;   

 /** 
 * @ORM\PrePersist
 */
public function prePersist(){
    $this->created = new \DateTime("now"); 
    $this->isDelete = 0;        
}

生成的架构:

+-----------+------------+------+-----+---------+----------------+
| Field     | Type       | Null | Key | Default | Extra          |
+-----------+------------+------+-----+---------+----------------+
| id        | int(11)    | NO   | PRI |         | auto_increment |
| isDeleted | tinyint(4) | YES  |     | 0       |                |
| created   | datetime   | YES  |     |         |                |
+-----------+------------+------+-----+---------+----------------+

任何想法?

参考

4

2 回答 2

2

您在上面的属性*之后缺少 a ,因此它不是 docblock 注释,并且 ergo 不会被解析为注释。因此,该领域没有被 Doctrine 认可。/*protected $created

它应该是:

/**
 * 
 * @ORM\Column (type="datetime")
 */
protected $created; 

修复此问题后,运行 Doctrine 架构更新工具。

于 2012-09-14T15:33:12.810 回答
1

你有没有* @ORM\HasLifecycleCallbacks()在你的班上名列前茅?

可能删除似乎有效,但您只能看到整数字段的默认值 (0)

于 2012-09-14T16:55:12.327 回答