我在 DOCTRINE 中使用日期作为数据类型,但它给了我这个错误:
Fatal error: Call to a member function format() on a non-object in C:xampphtdocstestdoctrinevendordoctrinedballibDoctrineDBALTypesDateType.php on line 53
这是我的代码:
/**
* private Date datePosted
* @Column(type="date")
* @AssertNotEmpty
*/
private $datePosted ;
当我将类型更改为字符串时,它工作正常。我该如何解决这个问题?
您的注释是错误的。
试试这个:
/**
* @var DateTime
* @ORMColumn(type="date", nullable=false)
*/
private $datePosted;
希望这有帮助。
编辑
您必须更新您的吸气剂和二传手(更改实体的YourEntityClass
)
/**
* Set datePosted
*
* @param DateTime $datePosted
* @return YourEntityClass
*/
public function setDatePosted($datePosted)
{
$this->datePosted = $datePosted;
return $this;
}
/**
* Get datePosted
*
* @return DateTime
*/
public function getDatePosted()
{
return $this->datePosted;
}