目录

Thinkphp5.0完美解决搜索后分页的BUG

目录

Thinkphp5.0完美解决搜索后分页的BUG

前端代码:

后端代码:

1.控制器层:

public function index(){

$RoleModel = new Role;

$condition = ‘’;

$keyword = input(‘search_name’);

if(!empty($keyword)){

$condition[’name’] = [’like’,’%’.$keyword.’%’];

}

$search = [‘query’=>[]];

$search[‘query’][‘search_name’] = $keyword;

$list = $RoleModel->getRoleList($condition,$search);

$this->assign(’list’,$list);

return $this->fetch();

}

Model层:

// 获取角色列表

public function getRoleList($condition,$search){

return $this->where($condition)

->paginate(10,false,$search);

}