博客园站长
这是人类成长进步中记录的每一时刻

 

 

写在这个文件下面操作

正常模式

db('user')->where('status',1)->select(); 查询状态为1的用户信息

在 Query.php下新增函数
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);

  

 

posted on 2020-03-25 10:13  dm3344  阅读(526)  评论(0)    收藏  举报