這個問題在過去的幾個小時裏一直讓我瘋狂。我添加的屬性posts_published_date我用戶實體(它跟蹤特定用戶發了一個帖子最後日期)。下面是一些相關線路:學說不在我的實體中加載或保存特定屬性
初始化在實體的屬性。
/**
* @Column(type="integer", length=3, nullable=false)
*/
protected $posts_published_today;
/**
* @Column(type="string", length=7, nullable=true)
*/
protected $posts_published_date;
/**
* @Column(type="integer", length=3, nullable=true)
*/
protected $posts_published_limit;
在實體使用屬性:
public function setPostsPublishedToday($value){
$today = date("now");
if ($today != $this->posts_published_date){
$this->posts_published_today = 1;
debug($this->posts_published_date . " != " . $today, "1");
$this->posts_published_date = $today;
debug($this->posts_published_date . " == " . $today, "2");
} else {
$this->posts_published_today = $value;
}
}
兩個(1)調試與下面的輸出運行:
Debug 1: != 220136
Debug 2: 220136 == 220136
的posts_published_date沒有得到存儲在數據庫中,但posts_published_today正在檢索並保存好。
您應該添加在這種情況下使用的代碼。 另外,考慮對'posts_published_date'屬性使用''datetime''字段類型,然後最終爲其分配一個'DateTime'對象。 – Ocramius 2013-02-16 22:34:18