.php文件不能带有数字
过滤不要字段
u
s
e
r
=
n
e
w
U
s
e
r
(
user = new User(
user=newUser(_POST);
// 过滤post数组中的非数据表字段数据
$user->allowField(true)->save();
分页
$user->save();
$result =
u
s
e
r
−
>
a
l
l
o
w
F
i
e
l
d
(
t
r
u
e
)
−
>
s
a
v
e
(
user->allowField(true)->save(
user−>allowField(true)−>save(data, [‘id’ => $id]);
不要在一个模型实例里面做多次更新,会导致部分重复数据不再更新,正确的方式应该是先查询后更
新或者使用模型类的 update 方法更新。
如果你调用save方法进行多次数据写入的时候,需要注意,第二次save方法的时候必须使用
isUpdate(false),否则会视为更新数据。
实例化模型后调用save方法表示新增;
查询数据后调用save方法表示更新;
save方法传入更新条件后表示更新;
当更新的数据一样,即使条件不一致时,save方法也不会更新数据。
解决方法:
加上isUpdate(true)更新数据。
t h i s − > i s U p d a t e ( t r u e ) − > s a v e ( [ ′ s c o r e ′ = > this->isUpdate(true)->save(['score'=> this−>isUpdate(true)−>save([′score′=>v[‘score’]],[‘id’=>$v[‘id’]]);
tp5默认软删除是int型,修改为datetime
在model的子文件定义
protected $autoWriteTimestamp = ‘datetime’;
protected $updateTime = false;
protected $dateFormat = ‘Y-m-d H:i:s’;