我在 symfony2 中创建了一个实体,并将实体设置为 createddatetime 和 updateddatetime,但是当我在控制器中使用 setter 时,错误发生如下
FatalErrorException: Error: Call to a member function format() on a non-object in C:\wamp\www\QuickBacklog\vendor\doctrine\dbal\lib\Doctrine\DBAL\Types\DateTimeType.php line 44
这是我的实体代码:
/**
* Set createdDatetime
*
* @param \DateTime $createdDatetime
* @return Sections
*/
public function setCreatedDatetime($createdDatetime)
{
$this->createdDatetime = $createdDatetime;
return $this;
}
/**
* Get createdDatetime
*
* @return \DateTime
*/
public function getCreatedDatetime()
{
return $this->createdDatetime;
}
/**
* Set updatedDatetime
*
* @param \DateTime $updatedDatetime
* @return Sections
*/
public function setUpdatedDatetime($updatedDatetime)
{
$this->updatedDatetime = $updatedDatetime;
return $this;
}
/**
* Get updatedDatetime
*
* @return \DateTime
*/
public function getUpdatedDatetime()
{
return $this->updatedDatetime;
}
但是当我在控制器中写
$date=date('Y-m-d H:i:s');
$entity->setCreatedDatetime($date);
$entity->setUpdatedDatetime($date);
发生错误我如何消除此错误?