Thinkphp 根据分页符实现文章分页

浏览:3849 发布日期:2015/02/05 分类:技术分享 关键字: 分页
//内容页
    public function detail(){
            //新闻内容start
$pagecode = "/<pagebreak>(.*?)<\/pagebreak>/is";
       $pagestart = I('request.p')==0?1:I('request.p');
         $map['id'] =I("request.id");
       $map['published'] = 1;
         $arc = D('News')->get_one($map);
       if(!$arc){
         $this->_empty();
         exit;
       }
              $arc['content'] = htmlspecialchars_decode($arc['content']);
         $content_array = preg_split($pagecode,$arc['content']);

         $counts = count($content_array);
       if($content_array[0]){
          $count = $counts;
          $pagestart = $pagestart-1;
       }else{
         $count = $counts-1;
           
       }
     //  echo  $pagestart;
         $p = new \Think\Page($count,1);  // 实例化分页类 传入总记录数和每页显示的记录数(25)
         //$p->url = "/^news\/(\d+)\_(\d+)$/";
     $p->setConfig('header','<span class="rows">共 %TOTAL_ROW% 页</span>');
     $p->setConfig('prev',"上一页");
     $p->setConfig('next','下一页');
     $p->setConfig('first','首页');
     $p->setConfig('last','最后一页');
     $p->setConfig('theme','  %up_page%  %link_page%  %down_page%  %end%');
     $p->search =  false;
     $p->url = '/news/'.I("request.id")."_";
     //var_dump($p);
     $show= $p->show();// 分页显示输出
        if($count==1){
            $this->assign("content",$content_array[0]);
        }else{
            $this->assign("content",$content_array[$pagestart]);
        }

        $this->assign("arc_page",$show);
     $this->assign("count",$count);
     $this->assign("arc",$arc);
}
<pagebreak>这个为分页符标识
需要开启分页路由'/^news\/(\d+)$/'          =>  'news/detail?id=:1',同时修改下page.class.php
page.class.php共享在附件中

www.wanyx.com/news/47274.html

附件 Page.class.zip ( 2.72 KB 下载:133 次 )

最佳答案
评论( 相关
后面还有条评论,点击查看>>