?php namespace app\common\model; use think\Model; use think\Db; class User extends Model{ //開啟自動完成時間戳功能 protected $autoWriteTimestamp = true; } ?>
User::update(['name'='安陽'],['id'=>1]);
Thinkphp中update方法的源代碼如下:
/** * 更新數(shù)據(jù) * @access public * @param array $data 數(shù)據(jù)數(shù)組 * @param array $where 更新條件 * @param array|true $field 允許字段 * @return $this */ public static function update($data = [], $where = [], $field = null) { $model = new static(); if (!empty($field)) { $model->allowField($field); } $result = $model->isUpdate(true)->save($data, $where); return $model; }
$user=new User; $user->isUpdate(true)->save(['name'='安陽'],['id'=>1]);
到此這篇關(guān)于thinkphp5.1的model模型自動更新update_time字段實例講解的文章就介紹到這了,更多相關(guān)thnikphp5.1的model模型自動更新update_time字段內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!