如果你想使用TP5里边的save()
方法进行更新数据,如果按照一般情况使用where()判断更新条件的话就会出现以下报错:
类似以下代码:
r e s = m o d e l ( ′ C e s h i ′ ) − > w
h e r e ( [ ′ u i d ′ = > res =
model('Ceshi')->where(['uid'=>res=model(′Ceshi′)−>where([′uid′=>uid])->allowField(true)->isUpdate(true)->save([‘status’=>1]);
1
正确的解决方式:
如果使用模型更新操作的时候不要使用where()来进行判断,需要使用isUpdate()
来判断,第一个参数是true,第二个参数写更新的条件。
r e s = m o d e l ( ′ C e s h i ′ ) − > a
l l o w F i e l d ( t r u e ) − > i s U p d a t e ( t r u e , [
′ u i d ′ = > res =
model('Ceshi')->allowField(true)->isUpdate(true,['uid'=>res=model(′Ceshi′)−>allowField(true)−>isUpdate(true,[′uid′=>uid])->save([‘status’=>1]);
1
或者是在save()的第二个参数加上更新条件
r e s = m o d e l ( ′ C e s h i ′ ) − > a
l l o w F i e l d ( t r u e ) − > i s U p d a t e ( t r u e ) −
> s a v e ( [ ′ s t a t u s ′ = > 1 ] , [ ′ u i d ′ = >
res =
model('Ceshi')->allowField(true)->isUpdate(true)->save(['status'=>1],['uid'=>res=model(′Ceshi′)−>allowField(true)−>isUpdate(true)−>save([′status′=>1],[′uid′=>uid]);
1
或者你用的是id主键字段为更新条件的话可以直接放在一个数组里边:
$res = model(‘Ceshi’)->allowField(true)->isUpdate(true)->save([‘status’=>1,‘id’=>1]);
https://blog.csdn.net/RSFeegg/article/details/107090308
加载中,请稍候......