Symfonty报 type string to type datetime错误

因为表的字段设置的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对象(还没有语句执行)
            $this->em->persist($obj);
            // 真正执行语句(如,INSERT 查询)
            $this->em->flush();
            $this->em->getConnection()->commit();
            return true;
        }catch (Exception $exception){
            $this->em->getConnection()->rollBack();
            return false;
        }

当然$obj->setGmtModified();是已经生成好的方法;

你可能感兴趣的:(Symfonty报 type string to type datetime错误)