模型自动加载时间戳字段

模型一般默认有个两个时间字段。一个是添加时间,一个是修改时间 。我这个是基于tpshop该的 这是model.php 调用updatetime ,如图下意思就是 如果模型定义这个update_time字段 并且添加的时候会检测要添加的数组是否有update_time 这个字段。

if ($this->autoWriteTimestamp && $this->updateTime && (empty($this->change) || !in_array($this->updateTime, $this->change))) {
$this->setAttr($this->updateTime, null);
}

我是这样解决的,直接在模型里面定义。

模型自动加载时间戳字段

getupdateTimeAttr 是获取这个字段,setUpdateTimeAttr是写入这个字段(我这里面判断写入这个字段是否为空如果为空就return null ,注意:如果不return空的话数据库会自动把当前时间写入数据库的)

模型自动加载时间戳字段

这里会有两个字段 并且时间戳一样。

只为自己看

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-09
  • 2021-11-20
  • 2022-01-29
  • 2022-12-23
猜你喜欢
  • 2022-01-08
  • 2021-09-02
  • 2021-07-02
  • 2022-12-23
  • 2022-01-08
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案