CI分页类-易于调用和定制(仅供参考)
不多说。主要是想分享一下上代码<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* @author joe <[58307280@qq.com]>
* 分页类
*/
class Page {
private $CI;
private $base_url;
private $total_rows;
private $per_page;
private $url_suffix;
public function __construct() {
$this->CI = & get_instance();
}
public function initialize($params) {
$this->url_suffix = $this->CI->config->item('url_suffix');
foreach ($params as $key => $value) {
$this->$key = $value;
}
}
public function create_links() {
$cur_page = ($cur_page = $this->CI->uri->get('page'))?$cur_page:1; // 获取当前页
$page_end = ceil($this->total_rows/$this->per_page);
$html = '<div class="page">';
$html .= '<a href="'.$this->base_url.'/1'.$this->url_suffix.'">« First</a>';
for ($i=1; $i < $cur_page+8 ; $i++) {
if ($i == $cur_page) {
$html .= '<a class="cur">'.$i.'</a>';
} elseif ($i <= $page_end) {
$html .= '<a class="num" href="'.$this->base_url.'/'.$i.$this->url_suffix.'">'.$i.'</a>';
}
}
$html .= '<a href="'.$this->base_url.'/'.$page_end.$this->url_suffix.'">Last »</a>';
return $html;
}
}
自己坐沙发:victory: 调用示例
$this->load->library('page');
$config['base_url'] = base_url(array('admin','login_log','page'));
$config['total_rows'] = $this->db->count_all('admin_login_log');
$config['per_page'] = 18;
$this->page->initialize($config);
$page = intval($this->uri->get('page'));
$page = (($page-1)<0?0:$page-1)*$config['per_page'];
$this->db->from('admin_login_log');
$this->db->limit($config['per_page'],$page);
$query = $this->db->get();
return $query->result_array(); {:1_1:}
页:
[1]