Home  >  Q&A  >  body text

ThinkPHP5 gets the timestamp and automatically converts it BUG, ​​please give me some advice?

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:

伊谢尔伦伊谢尔伦2716 days ago873

reply all(2)I'll reply

  • 世界只因有你

    世界只因有你2017-06-05 11:09:42

    比如这个是你的模型
    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());
    

    reply
    0
  • 为情所困

    为情所困2017-06-05 11:09:42

    Consider adding it after line 433

    $time = strtotime($time)!==false?strtotime($time):$time;

    reply
    0
  • Cancelreply