因為表的字段設置的timestamp類型,在使用date('Y-m-d H:i:s',time())插入日期時間時報錯如下:
clipboard.png
解決方案:
$time=date_create(date('Y-m-d H:i:s',time()))
$obj->setGmtModified($time);
try{
/// 告訴Doctrine你希望(最終)存儲obj對象(還沒有語句執(zhí)行)
$this->em->persist($obj);
// 真正執(zhí)行語句(如,INSERT 查詢)
$this->em->flush();
$this->em->getConnection()->commit();
return true;
}catch (Exception $exception){
$this->em->getConnection()->rollBack();
return false;
}
當然$obj->setGmtModified();是已經(jīng)生成好的方法统屈;