我很難分揀這個問題。我收到以下錯誤,而試圖堅持一個實體(見下文源):Symfony + Doctrine 2.2日期時間列錯誤
Fatal error: Call to a member function format() on a non-object
in *****\vendor\doctrine-dbal\lib\Doctrine\DBAL\Types\DateTimeTzType.php
on line 64
這裏的實體的代碼片段:
namespace ****\Bundle\****Bundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* ****\Bundle\****Bundle\Entity\MyEntity
*
* @ORM\Table()
* @ORM\Entity(repositoryClass="****\Bundle\****Bundle\Entity\****Repository")
* @ORM\HasLifecycleCallbacks()
*/
class MyEntity
{
/**
* @var integer $id
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var \DateTime $created_at
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $created_at;
/**
* @var \DateTime $updated_at
*
* @ORM\Column(name="updated_at", type="datetime", nullable="true")
*/
private $updated_at;
/**
* Set created_at
*
* @param datetime $createdAt
*/
public function setCreatedAt($createdAt)
{
$this->created_at = $createdAt;
}
/**
* Get created_at
*
* @return datetime
*/
public function getCreatedAt()
{
return $this->created_at;
}
/**
* Set updated_at
*
* @param datetime $updatedAt
*/
public function setUpdatedAt($updatedAt)
{
$this->updated_at = $updatedAt;
}
/**
* Get updated_at
*
* @return datetime
*/
public function getUpdatedAt()
{
return $this->updated_at;
}
/**
* @ORM\PrePersist()
*/
public function executePrePersist()
{
$this->created_at = new \DateTime();
}
/**
* @ORM\PreUpdate()
*/
public function executePreUpdate()
{
$this->updated_at = new \DateTime();
}
}
張貼在這裏,我添加之前:
print_r(get_class($value))
到DateTimeTzType.php在違規的地方就知道它收到的數據種類,我得到了以下錯誤:
Warning: get_class() expects parameter 1 to be object, string given
所以它似乎接收一個字符串而不是一個DateTime對象,然後失敗,因爲字符串沒有format()方法。
我正在使用Symfony 2.0.9。我錯過了什麼嗎?