OneThink框架的文章详情页分页
Application/Home/Controller/ArticleController.class.php的detail函数修改结果如下:
/* 文档模型详情页 */
public function detail($id = 0, $p = 1){
/* 标识正确性检测 */
if(!($id && is_numeric($id))){
$this->error('文档ID错误!');
}
/* 页码检测 */
$p = intval($p);
$p = empty($p) ? 1 : $p;
/* 获取详细信息 */
$Document = D('Document');
$info = $Document->detail($id);
if(!$info){
$this->error($Document->getError());
}
$content_array=explode('##分页##',$info['content']);
if(count($content_array)>1){
$info['content']=$content_array[$p-1];
$parse="";
for($i=1;$i<=count($content_array);$i++){
$parse.="<li><a href=".U('Article/detail',array('id'=>$info['id'],'page'=>$i)).">".$i."</a></li>";
}
$this->assign('page_string',$parse);
}
/* 分类信息 */
$category = $this->category($info['category_id']);
/* 获取模板 */
if(!empty($info['template'])){//已定制模板
$tmpl = $info['template'];
} elseif (!empty($category['template_detail'])){ //分类已定制模板
$tmpl = $category['template_detail'];
} else { //使用默认模板
$tmpl = 'Article/'. get_document_model($info['model_id'],'name') .'/detail';
}
/* 更新浏览数 */
$map = array('id' => $id);
$Document->where($map)->setInc('view');
/* 模板赋值并渲染模板 */
$this->assign('category', $category);
$this->assign('info', $info);
$this->assign('page', $p); //页码
$this->display($tmpl);
}
在后台添加文章的时候,在需要分页的地方插入 ##分页##
视图部分分页代码为:
<div class="pagination">
<ul>
{$page_string}
</ul>
</div>
基本思路:是把文章的content字段内容,分割为数组元素,根据传入p参数值的不同,显示数组不同的元素。
最新文章
- 【MSP是什么】MSP认证之项目集与项目群的关系和区别
- webstorm自动编译typescript
- 【Linux】/dev/null 2>;&;1 详解
- 在IE6下使用filter设置png背景
- plupload上传插件在SpringMVC中的整合
- 【Linux/Ubuntu学习5】Ubuntu 下android 开发,eclipse不能识别手机
- Extension Methods
- assert()用法
- SPOJ 375 树链剖分
- A*算法实现
- 控制结构(10): 指令序列(opcode)
- 用crontab部署定时任务
- 010Edit手写PE
- 用flask实现的分页
- 【转载】jdk1.8 LongAdder源码学习
- deepin中Tomcat添加执行权限
- Vue子组件调用父组件的方法
- mongodb 的一些基本命令以及 导入、导出,待更新
- LINUX CentOS7安装字体库
- Operating System-Thread(3)用户空间和内核空间实现线程
热门文章
- 如何使主机和虚拟机IP处于同一网段(内网渗透专用)
- POJ 1002 487-3279 (map )
- Linux eject弹出光驱
- python面向对象——类和对象
- Symfony2之创建一个简单的web应用 Symfony2——创建bundle
- request threaded-only IRQs with IRQF_ONESHOT【转】
- express 4.x+ swig
- [ Python - 4 ] python 装饰器
- xshell连接虚拟机CentOS出现eth0 device not found的解决方法
- poj 2242(已知三点求外接圆周长)