模型一般默认有个两个时间字段。一个是添加时间,一个是修改时间 。我这个是基于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空的话数据库会自动把当前时间写入数据库的)
这里会有两个字段 并且时间戳一样。
只为自己看