Doctrine 2:在DateTimeType.php中的非对象上调用成员函数format() [英] Doctrine 2: Call to a member function format() on a non-object ... in DateTimeType.php
本文介绍了Doctrine 2:在DateTimeType.php中的非对象上调用成员函数format()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 DateTime
字段:
/**
* Date time posted
* @Column(type="datetime")
*/
private $dtPosted;
使用LifeCycleCallback将其设置为默认值
which is set to a default value by using a LifeCycleCallback
/**
* @PrePersist
*/
function onPrePersist() {
// set default date
$this->dtPosted = date('Y-m-d H:m:s');
我收到以下错误:
致命错误:调用
中的成员函数
格式()
中的对象D:\ResourceLibrary\Frameworks\Doctrine\lib\Doctrine \DBAL\Types\DateTimeType.php
第46行
Fatal error: Call to a member function format() on a non-object in D:\ResourceLibrary\Frameworks\Doctrine\lib\Doctrine\DBAL\Types\DateTimeType.php on line 46
推荐答案
date()
函数返回一个字符串。 datetime
类型适用于 DateTime
对象。因此,将映射类型更改为 string
或使用 DateTime
对象。
The date()
function returns a string. The datetime
type works with DateTime
objects. So either change the mapping type to string
or use DateTime
objects.
这篇关于Doctrine 2:在DateTimeType.php中的非对象上调用成员函数format()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文