Codeigniter 配置 用 $_GET 参数 per_pager 设置翻页

使用 URI Segments 获取翻页参数,这种方法每次都需要添加路由,用 query_strings 则无需配置路由

配置如下代码 1. 上下翻页两个按钮

/**
* @function getPager 获取翻页配置数据,在model中获取列表数据中使用
*/
    protected function setPager($total_rows)
    {
        $this->load->library('pagination');

        $config['base_url']             = site_url($this->router->class);
        $config['total_rows']           = $total_rows;
        $config['per_page']             = 10;
        $config['enable_query_strings'] = true;
        $config['page_query_string']    = true;
        $config['reuse_query_string']   = true;
        $config['display_pages']        = false;
        $config['use_page_numbers']     = true;
        $config['prev_link']            = '上一页';
        $config['prev_tag_open']        = '<li class="previous">';
        $config['prev_tag_close']       = '</li>';
        $config['next_link']            = '下一页';
        $config['next_tag_open']        = '<li class="next">';
        $config['next_tag_close']       = '</li>';
        $config['first_link']           = '';
        $config['last_link']            = '';

        $pager['per_page'] = $config['per_page'];
        // 从 URI 中 读取页码参数
        $pager['curpage'] = $this->input->get('per_page') ? intval($this->input->get('per_page')) : 1;
        // 页码x每页数量 = 查询从第几条数据开始
        $pager['start_page'] = ($pager['curpage'] && is_numeric($pager['curpage']) && $pager['curpage'] > 1) ? ($pager['curpage'] - 1) * $pager['per_page'] : 0;

        $this->pagination->initialize($config);

        return $pager;
}