• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

CodeIgniter分页类pagination使用方法示例_PHP

php 搞代码 3年前 (2022-01-25) 13次浏览 已收录 0个评论

本文实例讲述了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    = <p>+本文来源gao!%daima.com搞$代*!码9网(</p><strong>搞gaodaima代码</strong>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['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(),    );}

希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:CodeIgniter分页类pagination使用方法示例_PHP
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址