不言不语

您现在的位置是: 首页 >  PHP

PHP

DateTime::__construct() expects parameter 1 to be string, int given

2022-06-05PHP
Thinkphp6.0的框架的情况下报错:DateTime::__construct() expects parameter 1 to be string, int given

报错:DateTime::__construct() expects parameter 1 to be string, int given

Thinkphp6.0的框架的情况下

->toArray();
return json(['code'=>0,'msg'=>'success','data'=>$data]);

只要对象转化为数组,都会报错,这里主要是涉及到时间格式的原因
Thinkphp6解决办法

方法一:(推荐)

找到配置文件database.php

找到

'auto_timestamp'  => true,

改成

'auto_timestamp'  => false,

方法二:

到当前模型下,加入以下代码

protected $autoWriteTimestamp = false;


文章评论