thinkphp5.0分頁


 第一種

public function index(){
        // 頁面和面包屑導航
        $ttl[0] = $this->title;
        $ttl[1] = '管理員列表';
        $this->assign('ttl',$ttl);
        // 權限驗證
        $this->admin_priv('role_index');

        $where = [];
     // 查詢條件
        $keyword = input('param.keyword');
        if($keyword){
            $where['name'] = ['like','%'.$keyword.'%'];
        }
        // 查詢
        $list = db("role")
            ->where($where)
            ->paginate(config('paginate.list_rows'));

        // 獲取分頁顯示
        $page = $list->render();

        // 模板變量賦值
        $this->assign('list', $list);
        $this->assign('page', $page);

        return $this->fetch();
    }

 第二種寫法:

public function index(){
        // 頁面和面包屑導航
        $ttl[0] = $this->title;
        $ttl[1] = '管理員列表';
        $this->assign('ttl',$ttl);
        // 權限驗證
        $this->admin_priv('role_index');


        // 查詢條件
        $keyword = input('param.keyword');
        $where['name'] = ['like','%'.$keyword.'%'];
        $fiels['keyword'] = $keyword;
        // 查詢
        $list = db("role")
            ->where($where)
            ->paginate(config('paginate.list_rows'));

        // 獲取分頁顯示
        $page = $list->render();

        // 模板變量賦值
        $this->assign('fiels', $fiels);

        $this->assign('list', $list);
        $this->assign('page', $page);

        return $this->fetch();
    }

這兩種只有細節方面的差別,其他都一樣

 

注意:

1.$where 的初始條件為 $where = []  

$where = 1   報錯:Illegal string offset 'name'

2.查詢數組兩種寫法,都可以

$where['name'] = ['like','%'.$keyword.'%'];

$where['name']=array('like','%'.$keyword.'%');


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM