zoukankan      html  css  js  c++  java
  • 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参数值的不同,显示数组不同的元素。

  • 相关阅读:
    连锁超市价格表 超市商品价格目录表
    无线路由器后台破解无需密码登录, 什么是网桥,怎么设置网桥
    做技术安卓开发程序员怎么赚钱
    QQ怎么 发送 已经录好的视频
    win 10 文件夹 背景 没效果
    夏婉安
    Navicat Premium 激活码 序列号。破解版。
    韩梦飞沙Android应用集合 想法
    安卓 开机 动画 酷派大神F1开机动画 美化 自定义 修改
    android 视频 2017
  • 原文地址:https://www.cnblogs.com/shanmao/p/4940722.html
Copyright © 2011-2022 走看看