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参数值的不同,显示数组不同的元素。

  • 相关阅读:
    silverlight 视频
    Win7/Vista下安装SQL Server 2005/2008后,进行附加数据库错误的解决
    IIS篇
    ARCGIS 定位篇
    sqlserver 2008 修改表结构不能保存
    更新silverlight 后 无法启动调试 未安装silverlight developer 运行时解决办法
    2点经纬度计算相对方位
    VS2010中文旗舰版在WIN7 64位操作系统下安装
    self = [super init]
    NSXMLParser XML 解析 解压
  • 原文地址:https://www.cnblogs.com/shanmao/p/4940722.html
Copyright © 2011-2022 走看看