wesky

 第一种

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.\'%\');

分类:

技术点:

相关文章:

  • 2021-07-12
  • 2022-01-04
  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
  • 2021-06-16
猜你喜欢
  • 2021-11-23
  • 2022-01-03
  • 2022-12-23
  • 2021-09-17
  • 2021-09-03
  • 2021-05-19
  • 2021-11-28
相关资源
相似解决方案