codeigniter 具有非常容易使用的分页类,在本教程中我会做一个从数据库教程返回一组结果并分页这些结果的简单例子,我将使用最新版本的 ci,分页类并没有修改,至少我认为没有,用最新的稳定版框架总是好的.
调用方法,代码如下:
-
-
$config = array();
-
$this->load->library('hpages');
-
$config['base_url'] = "channel/lists/c{$slug}/{page}";
-
$config['total_rows'] = intval($total);
-
$config['per_page'] = $pagesize;
-
-
$config['uri_segment'] = 1;
-
$config['num_links'] = 3;
-
$config['underline_uri_seg'] = 1;
-
$this->hpages->init($config);
-
$this->template['lists'] = $list;
-
$this->template['pagestr'] = $this->hpages->create_links(1);
php文件代码,实例如下:
-
<?php if (! defined('basepath')) exit('access denied!');
-
-
-
-
-
-
-
-
-
-
-
-
-
class hpages {
-
var $base_url = '';
-
var $total_rows = '';
-
var $per_page = 10;
-
var $num_links = 2;
-
var $cur_page = 1;
-
var $first_link = '‹ first';
-
var $next_link = '>';
-
var $prev_link = '<';
-
var $last_link = 'last ›';
-
var $uri_segment = 3;
-
var $full_tag_open = '';
-
var $full_tag_close = '';
-
var $first_tag_open = '';
-
var $first_tag_close = ' ';
-
var $last_tag_open = ' ';
-
var $last_tag_close = '';
-
var $cur_tag_open = ' <b>';
-
var $cur_tag_close = '</b>';
-
var $next_tag_open = ' ';
-
var $next_tag_close = ' ';
-
var $prev_tag_open = ' ';
-
var $prev_tag_close = '';
-
var $num_tag_open = ' ';
-
var $num_tag_close = '';
-
var $page_query_string = false;
-
var $query_string_segment = 'per_page';
-
-