OneThink框架的文章详情页分页
2015-11-05 20:36
302 查看
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参数值的不同,显示数组不同的元素。
/* 文档模型详情页 */
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参数值的不同,显示数组不同的元素。
相关文章推荐
- ubuntu下软件管理
- cannot convert parameter 1 from 'const char [] ' to 'const wchar_t * '的解决方法
- HDU 2222 Keywords Search (AC自动机)
- hihocoder 1110 正则表达式
- scala实现插入排序
- 为kali 2.0 安装 VMware tools
- Activity Task相关
- 冒泡排序的推导
- Linux内存
- 【OpenCV】计算图像的水平和垂直积分投影
- OC初期-05字典,集合
- Linux内存
- Linux内存
- 归档、解归档(序列化、反序列化)
- 玩转树莓派--GPIO操作
- keepalived入门之配置文件详解(3)
- 设计模式:模版模式(Template Pattern)
- 【174】C#添加非默认字体
- request body stream exhausted错误解决方案
- Codeforces Round #329 (Div. 2)