Thinkphp5.0完美解決搜尋後分頁的BUG
前端程式碼:
<form method="get" action="{:url('Roles/index')}">
<div class="input-group input-group-sm" style="width: 150px;">
<input type="text" name="search_name" class="form-control pull-right" placeholder="Search name..." />
<div class="input-group-btn">
<button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
</div>
</div>
</form>
後端程式碼:
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);
}