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();
}
第二种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();
}
这两种只有细节方面的差别,其他都一样 $where = [] 这个位置注意:
1.$where 的初始条件为 $where = []
$where = 1 报错:Illegal string offset 'name'
2.查询数组两种写法,都可以
$where['name'] = ['like','%'.$keyword.'%'];
$where['name']=array('like','%'.$keyword.'%');
最佳答案
