您的位置:首页 > 编程语言 > PHP开发

CI框架---分页

2016-09-03 16:10 267 查看
public function getUserData(){

//连接数据库
$this->load->database();

//实列化模型
$this->load->model('user_model','user');

//获取user表总记录数
$total=$this->user->getCount();
$perpage=2;

//载入分页类
$this->load->library('pagination');
//配置分页类连接
$config['base_url'] =site_url('user/getUserData');
//分页设置
$config['total_rows'] =$total;
$config['per_page'] =$perpage;
//设置上下页
$config['next_tag_open'] = '<font color="red">';
$config['next_tag_close'] = '</font>';

$config['prev_link']='上一页'; 
$config['next_link'] ='下一页';

//实例化
$this->pagination->initialize($config); 

//获取分页页码
$page=$this->pagination->create_links();
//设置偏移量
$offset=$this->uri->segment(3);

   //调用模型方法

$userData=$this->user->getUserData($perpage,$offset);

//获取配置文件中的路径设置

$viewPath=$this->config->item('viewPath');

//获取视图,赋值变量

$this->load->view('user/getUserData',array('userData'=>$userData,'viewPath'=>$viewPath,'page'=>$page));
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  框架 php