gpt4 book ai didi

php - Doctrine 2 : Call to a member function format() on a non-object . .. 在 DateTimeType.php

转载 作者:IT王子 更新时间:2023-10-29 01:12:50 25 4
gpt4 key购买 nike

我有一个 DateTime 字段:

/**
* Date time posted
* @Column(type="datetime")
*/
private $dtPosted;

使用 LifeCycleCallback 将其设置为默认值

/**
* @PrePersist
*/
function onPrePersist() {
// set default date
$this->dtPosted = date('Y-m-d H:m:s');

我收到以下错误:

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 对象。

关于php - Doctrine 2 : Call to a member function format() on a non-object . .. 在 DateTimeType.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3378748/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com