找了一下开发文档,没找到有分页的读取数据库的简单类,只能自己算limit了
/
config/pagination.php
分页配置
-----
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['uri_segment'] = 4;//页码节
$config['num_links'] = 5; //页码左右个数
$config['full_tag_open'] = '<p>';//整个页面条左侧。
$config['full_tag_close'] = '</p>';//整个页码条右侧。
$config['first_link'] = '首页';//第一页名字
$config['first_tag_open'] = '<span>';//首页的左边
$config['first_tag_close'] = '</span>';//首页的右边
$config['last_link'] = '尾页';//尾页名字
$config['last_tag_open'] = '<span>';//尾页左边
$config['last_tag_close'] = '</span>';//尾页右边
$config['prev_link'] = '上页';//上页名字
$config['prev_tag_open'] = '<span>';//上页左边
$config['prev_tag_close'] = '</span>';//上页右边
$config['next_link'] = '下页';//下一页名字
$config['next_tag_open'] = '<span>';//下页左边
$config['next_tag_close'] = '</span>';//下页右边
$config['cur_tag_open'] = '<b class=curPage >';//当前页左边
$config['cur_tag_close'] = '</b>';//当前页右边
$config['num_tag_open'] = '<span>';//活动数字页左边
$config['num_tag_close'] = '</span>';//活动数字页右边
$config['display_pages'] = TRUE; //不需要数字页,只上下页,FLASE
$config['anchor_class'] = 'page';//活动页码类名
$config['per_page'] = '2'; //页条数
---------------------------
controllers/xxx.php
控制器代码
----------
$this->load->library('pagination');
$config['base_url'] = site_url('test/init/sys_log/');
$config['total_rows'] = $this->db->count_all('sys_log');
$this->pagination->initialize($config);
$data['pageCode'] = $this->pagination->create_links();
$page = (int)$this->uri->segment(4, 0);
$page && $page = 1;
$pagePer = $this->config->item('per_page');
$pagePer && $pagePer = 20;
$this->db->select('*')->from('sys_log')->order_by('id DESC')->limit($pagePer, $page*$pagePer);
$data['lists'] = $this->db->get()->result_array();
$this->load->view('houtai/sys_log', $data);
----------
view/xxx.php
视图文件
-----------
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>系统日志</title>
<?php echo link_tag('styles/screen.css'); ?>
<?php echo link_tag('test/styles/main.css'); ?>
</head>
<body>
<div id="bodyDiv">
<fieldset>
<legend>系统日志</legend>
<?php if (isset($tip)){ echo '<div style="color:red;">' .$tip. '</div>'; } ?>
<table class="listTable" >
<tr>
<th>
<input οnclick="checkbox_all('id[]', this.checked)" type="checkbox" />
Id</th>
<th>日志内容</th>
<th>生成时间</th>
</tr>
<?php
foreach( $lists as $list){
echo "
<tr>
<td>
<input type=checkbox name=id[] value={$list['id']} />
{$list['id']}</td>
<td>" .htmlspecialchars($list['log']). "</td>
<td>" .date('Y-m-d H:I:s', $list['time']). "</td>
</tr>
";
}
?>
<tr>
<td >
<input type="button" value="删除" οnclick="delAll('test/init/sys_log/1')" />
</td>
<td colspan=2>
<?php echo $pageCode; ?>
</td>
</tr>
</table>
</fieldset>
</div>
</body>
</html>
<script>var site_url = '<?php echo base_url();?>'; </script>
<?php echo scriptSrc('scripts/public.js'); ?>
-------------
效果
--------