资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

CodeIgniter中如何使用pagination分页类-创新互联

这篇文章给大家介绍CodeIgniter中如何使用pagination分页类,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

成都创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站建设、网站制作、扬州网络推广、微信小程序定制开发、扬州网络营销、扬州企业策划、扬州品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们大的嘉奖;成都创新互联为所有大学生创业者提供扬州建站搭建服务,24小时服务热线:13518219792,官方网址:www.cdcxhl.com

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(),
    );
}

关于CodeIgniter中如何使用pagination分页类就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。


文章名称:CodeIgniter中如何使用pagination分页类-创新互联
网站路径:http://cdkjz.cn/article/dejhjo.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220