CI分页配置/使用

找了一下开发文档,没找到有分页的读取数据库的简单类,只能自己算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'); ?>

-------------

效果

--------

CI分页配置/使用 - qidizi - qidizi 的博客

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值