|
本帖最后由 myzingy 于 2010-3-20 10:48 编辑
分享带搜索的分页使用心得,欢迎拍砖,谁要有更好的思路,热情期待
地址需要构造为 类似下面
http://www.***.com/index.php/auth/admin/members/index/搜索字段/值/搜索字段/值/.../page/10
如:http://www.***.com/index.php/auth/admin/members/index/username/myzingy/email/goto999@126.com
控制层代码如下
$url_param=$this->uri->uri_to_assoc(1);// url获取参数
$fileds=array('username','email','group'); //搜索字段
$where=NULL;
foreach($fileds as $k){ //构造where 数组
if(!empty($url_param[$k])){
$where[$k]=$url_param[$k];
}
}
$page=$url_param['page']+0; //当前page
$url_param['page']=NULL; //清空此配置
$url_param=$this->uri->assoc_to_uri($url_param);
/*
封装为搜索url,这里需要修改/system/libraries/URI.php #430 assoc_to_uri 函数
foreach ((array)$array as $key => $val)
{
if(!$val) continue; //增加这里,过滤空值
$temp[] = $key;
$temp[] = $val;
}
*/
$this->load->library('pagination');
$config['base_url'] = base_url()."/index.php/{$url_param}/page";
$config['total_rows'] = $this->user_model->getUsers($where,NULL,true);//获取会员总数
$config['per_page'] = '10';
$config['cur_page'] = $page;/*指定当前page,因page参数位置可能是变化的,无法通过$config['uri_segment'] = * 设置; */
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
// Get Member Infomation
$limit=array('offset'=>$page,'limit'=>$config['per_page']);
$data['members'] = $this->user_model->getUsers($where,$limit); |
|