CodeIgniter分页类pagination使用方法示例
发布:smiling 来源: PHP粉丝网 添加日期:2021-07-21 18:06:09 浏览: 评论:0
这篇文章主要介绍了CodeIgniter分页类pagination使用方法,结合实例形式简单分析了CodeIgniter框架中的分页类pagination基本的配置与使用技巧,需要的朋友可以参考下。
本文实例讲述了CodeIgniter分页类pagination使用方法,分享给大家供大家参考,具体如下:
controller控制器(application/controller/page.php文件):
- public function index()
- {
- $this->load->model ( 'home_model' , '' , TRUE);
- $config= array();
- $config['per_page'] = $this->per_page; //每页显示的数据数
- $current_page = intval($this->input->get_post('per_page',true)); //获取当前分页页码数
- //page还原
- if(0 == $current_page)
- {
- $current_page = 1;
- }
- $offset = ($current_page - 1 ) * $config['per_page']; //设置偏移量 限定 数据查询 起始位置(从 $offset 条开始)
- $result = $this->home_model->index($offset,$config['per_page'],$order='id desc');
- $config['base_url'] = $this->config->item('base_url').'admin/home/index?';
- $config['first_link'] = $this->first_link;//首页
- $config['prev_link'] = $this->prev_link;//上一页
- $config['next_link'] = $this->next_link;//下一页
- $config['last_link'] = $this->last_link;//尾页
- $config['total_rows'] = $result['total'];//总条数
- $config['num_links'] = 3;//页码连接数
- $config['use_page_numbers'] = TRUE;
- $config['page_query_string'] = TRUE;
- $this->load->library('pagination');//加载ci pagination类
- $this->pagination->initialize($config);
- $result = array(
- 'list' => $result['list'],
- 'total' => $result['total'],
- 'current_page' => $current_page,
- 'per_page' => $config['per_page'],
- 'page' => $this->pagination->create_links(),
- );
- $this->load->view ( 'admin/home' , $result );
- }
model模型(application/model/home_model.php文件):
- public function index($offset,$num,$order='id desc')
- {
- $query = $this->db->query( "SELECT Name_cn,Mall_type,create_time FROM smzdm_mall WHERE Is_deleted = 0 order by {$order} limit {$offset},{$num}");
- return array(
- 'total' => $this->db->count_all('smzdm_mall',array('Is_deleted'=>'0')),
- 'list' => $query->result(),
- );
- }
Tags: CodeIgniter分页类 pagination
推荐文章
热门文章
最新评论文章
- 写给考虑创业的年轻程序员(10)
- PHP新手上路(一)(7)
- 惹恼程序员的十件事(5)
- PHP邮件发送例子,已测试成功(5)
- 致初学者:PHP比ASP优秀的七个理由(4)
- PHP会被淘汰吗?(4)
- PHP新手上路(四)(4)
- 如何去学习PHP?(2)
- 简单入门级php分页代码(2)
- php中邮箱email 电话等格式的验证(2)