CI伪静态分页
2016-04-08 18:17
211 查看
首先在 httpd.conf 开启重写规则
控制器 welcome.php
展示模板 show.php
.htaccess
控制器 welcome.php
<?php defined('BASEPATH') OR exit('No direct script access allowed'); class Welcome extends CI_Controller { /** * Index Page for this controller. * * Maps to the following URL * http://example.com/index.php/welcome * - or - * http://example.com/index.php/welcome/index * - or - * Since this controller is set as the default controller in * config/routes.php, it's displayed at http://example.com/ * * So any other public methods not prefixed with an underscore will * map to /index.php/welcome/<method_name> * @see https://codeigniter.com/user_guide/general/urls.html */ public function index($page=1) { //求出总记录数 $count = $this->db->count_all('collect10'); //设置每页条数 $page_num = 3; //求出总页数 $num = ceil($count/$page_num); //求出偏移量 $start = ($page-1)*$page_num; //求出数组 $arr = $this->db->get('collect10',$page_num,$start)->result_array(); //获取分页数据 $last = $page==1?1:$page-1; $next = $page==$num?$num:$page+1; $list = "<a href='http://localhost/index_".$last.".html'>上一页</a>"; for($i=1;$i<=$num;$i++){ $list.="<a href='http://localhost/index_".$i.".html'>".$i."</a>"; } $list.="<a href='http://localhost/index_".$next.".html'>下一页</a>"; $data['arr'] = $arr; $data['list'] = $list; $this->load->view('show',$data); } }
展示模板 show.php
<table> <?php foreach ($arr as $k => $v): ?> <tr> <?php foreach ($v as $key => $value): ?> <td> <?php echo $value ?> </td> <?php endforeach ?> </tr> <?php endforeach ?> </table> <?php echo $list; ?>
.htaccess
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L]
相关文章推荐
- Unity3D中继承在ios上的UIApplicationDelegate
- final, finally, finalize
- 欢迎使用CSDN-markdown编辑器
- ORA-00600: internal error code, arguments: [kcratr_nab_less_than_odr], [1], [1498], [18713], [18720]
- 菜鸟学Java(二十)——你知道long和Long有什么差别吗?
- 构建之法阅读笔记6
- JavaPersistenceWithHibernate第二版笔记-第七章-004Mapping a map(@MapKeyEnumerated 、 @MapKeyTemporal、@MapKeyColumn)
- 0408送队友一个汉堡包
- ssh免密码登录
- 给每一行的修改加一个事件
- Python 格式化输出 ( 颜色 )
- LeetCode *** 101. Symmetric Tree
- QT5 OpenGL(七, 透明度设置)
- Android开发常见异常与错误系列(二)
- Lua中的loadfile,dofile,require使用,最后还有调试
- 在eclipse中设计BPMN 2.0工作流定义的根本步骤
- XStream xml与javabean之间的互转
- Unicode中文和特殊字符的编码范围
- Androidd Intent总结
- 【知识分享】有趣的乘法规律