ThinkPHP5 gets the timestamp and automatically converts it BUG, ​​please give me some advice?
伊谢尔伦
伊谢尔伦 2017-06-05 11:07:42
0
2
814

In TP5, use the model to obtain a piece of data, and then output the error. It is found that the timestamp is formatted by TP5 using the date () method, but the create_time set in my data table is of the timestamp type and is obtained. It is already a formatted string, so an error is reported. .

Later I saw an official method: set the datetime_format value to false to turn off automatic conversion output
But I tried it to no avail. What should I do? Can you be more specific?

Controller code:

Model code:

data sheet:

Error screenshot:

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all(2)
世界只因有你
比如这个是你的模型
namespace app\xxx\model;
use think\Model as ThinkModel;
use think\Db;

class XXX extends ThinkModel
{
    // 设置当前模型对应的完整数据表名称
    protected $table = 'XXXPPP';

    // 自动写入时间戳,这个是开关可以关闭
    protected $autoWriteTimestamp = true; 
    
    //这个可以覆盖的吧
    public function getCreteTimeAttr($time)
    {
        return $time;
    }
}
不过文档这里有写这个
$user = User::get(1);
// 通过获取器获取字段
echo $user->status;
// 获取原始字段数据
echo $user->getData('status');
// 获取全部原始数据
dump($user->getData());
为情所困

Consider adding it after line 433

$time = strtotime($time)!==false?strtotime($time):$time;
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!