tp allowField

allowField

也可以直接带更新条件来更新数据

$user = new User;
// save方法第二个参数为更新条件
$user->save([
    'name'  => 'thinkphp',
    'email' => 'thinkphp@qq.com'
],['id' => 1]);

如果需要过滤非数据表字段的数据,可以使用:

$user = new User();
// 过滤post数组中的非数据表字段数据
$user->allowField(true)->save($_POST,['id' => 1]);

如果你通过外部提交赋值给模型,并且希望指定某些字段写入,可以使用:

$user = new User();
// post数组中只有name和email字段会写入
$user->allowField(['name','email'])->save($_POST, ['id' => 1]);

 

posted @ 2020-08-05 18:44  孤陌  阅读(1109)  评论(0编辑  收藏  举报