您使用标准分页:/没关系,分页生成如下:
类/函数/分页编号
网址基础:
$config['base_url'] = 'http://moefoster.com/music/';
路线:
$route['music'] = 'music';
$route['music/(:num)'] = 'music/$1';
$route['default_controller'] = "music";
$route['(:any)'] = 'pages/view/$1';
但我在后端使用,\libraries\My_Pagination.php
<?php
if (! defined('BASEPATH')) exit('No direct script access allowed');
class MY_Pagination extends CI_Pagination
{
var $offset = 0;
var $pagination_selector = 'page';
var $index_page;
function MY_Pagination ()
{
parent::__construct();
log_message('debug', "MY_Pagination Class Initialized");
$this->index_page = config_item('index_page') != '' ? config_item('index_page') . '/' : '';
$this->_set_pagination_offset();
}
function _set_pagination_offset ()
{
$CI = & get_instance();
if (strstr($CI->uri->uri_string(), $this->pagination_selector)) {
$segments = $CI->uri->segment_array();
foreach ($segments as $key => $value) {
if ($value == $this->pagination_selector) {
$this->offset = $CI->uri->segment($key + 1);
$this->uri_segment = $key + 1;
$uri = $CI->uri->uri_string();
$pos = strpos($uri, $this->pagination_selector);
$this->base_url = '/'.$this->index_page . substr($uri, 0, $pos + strlen($this->pagination_selector.'/'));
}
}
}
else {
$this->offset = 0;
$this->uri_segment = 0;
$this->base_url = '/'.$this->index_page . $CI->uri->uri_string() . '/' . $this->pagination_selector.'/';
}
}
}
示例控制器
function somefunction($somevariable){
$config['total_rows'] = Model_Admin::getCountClankyCategory($somevariable);
$config['per_page'] = 25;
$config['cur_tag_open'] = '#START SOME HTML#';
$config['cur_tag_close'] = '#END SOME HTML#';
$config['full_tag_open'] = '#START SOME HTML PAGINATION#';
$config['full_tag_close'] = '#END SOME HTML PAGINATION#';
$this->pagination->initialize($config);
$data['content'] = Model_Admin::getAllClankyCategory($somevariable,$config['per_page'],$this->pagination->offset);
.....
}
一些示例模型
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Model_Admin extends CI_Model {
private static $db;
function __construct()
{
parent::__construct();
self::$db = &get_instance()->db;
}
static function getAllClankyCategory($cat,$num,$offset) {
self::$db->where('#MYTYPE#',$cat);
return self::$db->get('#SOMETABLE#',$num,$offset)->result_array();
}
static function getCountClankyCategory($cat) {
return self::$db->count_all_results('#SOMETABLE#');
}
那么如果你使用“一些硬代码路由”,比如路由,其他你使用没有这些路由
$route['admin/articles/cat/(:any)'] = "admin/cat/$1";
$route['admin/articles/cat/(:any)/(:num)'] = "admin/cat/$1/$2";