zoukankan      html  css  js  c++  java
  • HelpersPagination

    HelpersPagination

    Break recordset into a series of pages.

    First create a new instance of the class pass in the number of items per page and the instance identifier, this is used for the GET parameter such as ?p=2

    The setTotal method expects the total number of records, either set this or pass in a call to a model that will return records then count them on return.

    The method used to get the records will need a getLimit passed to it, this will then return the set number of records for that page.

    Lastly a method called page_links will return the page links.

    The model that uses the limit will need to expect the limit:

    public function getContacts($limit)
    {
        return $this->db->select('
            SELECT 
            *,
            (SELECT count(id) FROM '.PREFIX.'contacts) as total
         FROM '.PREFIX.'contacts '.$limit);
    }

    Pagination concept

    //create a new object
    $pages = new Paginator('1', 'p');
    
    //calling a method to get the records with the limit set (model would be the var holding the model data)
    $data['records'] = $this->model->getContacts($pages->getLimit());
    
    //set the total records, calling a method to get the number of records from a model
    $pages->setTotal($data['records'][0]->total);
    
    //create the nav menu
    $data['pageLinks'] = $pages->pageLinks();

    Usage example:

    $pages = new Paginator('50','p');
    $data['records'] = $this->model->getContacts($pages->getLimit());
    $pages->setTotal($data['records'][0]->total);  
    $data['pageLinks'] = $pages->pageLinks();
  • 相关阅读:
    数据分析之异常值分析-箱线图
    PHP学习路线图(转)
    学习简易爬虫设计(转)
    学习扫码登录的例子
    2017年PHP程序员未来路在何方(转)
    一个PHP开发APP接口的视频教程
    PHP实现Restful风格的API(转)
    大型网站技术架构-入门梳理(转)
    PHP面试总结(转)
    大型网站系统架构的演化(转)
  • 原文地址:https://www.cnblogs.com/chunguang/p/5643188.html
Copyright © 2011-2022 走看看