时间:2021-07-01 10:21:17 帮助过:71人阅读
public function unionWhere(){
return $this->where(‘status‘, 1);
}
链式追加
db(‘user‘)->unionWhere()->select(); 查询状态为1的用户信息
还可以传参配合switch
db(‘user‘)->applySql(1)->select(); 查询状态为1的用户信息
//动态追加排序条件
public function applySql($type)
{
switch ($type) {
case 1:
return $this->unionWhere();
break;
default:
return $this->sortActive(); //最后回复排序
break;
}
}
//最新帖子排序
public function unionWhere(){
return $this->where(‘status‘, 1);
}
//最后回复排序
public function sort2id()
{
return $this->order(‘id‘, ‘desc‘);
}
还可以直接改写 select/delete/xxx 等结尾函数,适用于SAAS模式,如:每次查询带 where (sid,xxx);

php tp5 语句后面链式追加sql语句
标签:code des ret function xxx mic where pre use