|
我在application的libraries里面新加了一个文件MY_Pagination.php,代码如下:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* 为了减少使用分页的代码,及统一设置分页菜单风格,自定义分页类,继承自CI_Pagination。
* 调用方式:
$config['counsql'] = '';
$config['listsql'] = '';
$config['per_page'] = 10;
$config['cur_page'] = 1;
$config['base_url'] = site_url('books/index');
$config['uri_segment'] = 3;
*/
class MY_Pagination extends CI_Pagination {
//定义基本变量
var $countsql = '';
var $listsql = '';
function MY_Pagination($params = array())
{
if(count($params)>0)
{
$this->initialize($params);
}
}
/**
* 初始化
*
* @param unknown_type $params
*/
function initialize($params = array())
{
if (count($params) > 0)
{
foreach ($params as $key => $val)
{
if (isset($this->$key))
{
$this->$key = $val;
}
}
}
}
function getTotalcount()
{
$CI =& get_instance();
$query = $CI->db->query($this->countsql);
return $query->num_rows();
}
/**
* 获取指定页的记录数组
*
*/
function getDataArray()
{
$sql = $this->listsql.' limit '.($this->cur_page-1)*$this->per_page.', '.$this->per_page;
$CI =& get_instance();
$query = $CI->db->query($sql);
if($query->num_rows()>0)
{
return $query->result_rows();
}
return '';
}
/**
* 获取分页工具栏
*
* @return unknown
*/
function getPageToolmenu()
{
$this->total_rows = $this->getTotalcount();
return $this->create_links();
}
}
?>
调用的地方
function searchcity($strcity)
{
if($strcity == '')
return '';
$pagination = $this->load->library('MY_Pagination');
$config['listsql'] = 'select cityname from addr_city ac where ac.cityname like \''.$strcity.'%\' or ac.pinyin like \''.$strcity.'%\'';
$config['cur_page'] = 1;
$config['per_page'] = 10;
$pagination->initialize($config);
return $pagination->getDataArray();
}
结果出现如下错误
Class 'CI_Pagination' not found in MY_Pagination.php on line 13 |
|