+ -
当前位置:首页 → 问答吧 → 发现新版TP官网blog例子分页bug

发现新版TP官网blog例子分页bug

时间:2011-05-08

来源:互联网



发现新版TP官网blog例子首页没有分页的bug
在BlogAction.class.php模块,我修正如下。分享给各位网友
public function index() {
            $Blog = D("BlogView");
            $count = $Blog->where("Blog.status=1")->count();//原先是 $count = $Blog->where("status=1")->count();,这样没有分页显示//
            echo "Mikko-".$count;//修改之前 $count=''
            $mode = "normal";
            if (isset($_REQUEST["mode"])) {
                $mode = $_REQUEST["mode"];
            }
            if ($mode == "list") {
                $listRows = 45;
                //$fields = 'id,title,categoryId,category,cTime,readCount,commentCount';
            }else {
                $listRows = 8;
                //$fields = 'id,title,categoryId,cTime,readCount,commentCount,content,tags';
            }
            import("@.ORG.Page");
            
            $p = new Page($count, $listRows);
            $p->setConfig("header", "篇日志");
            $this->assign("mode", $mode);
//以下红色代码也应该加上,否则不符合逻辑
            $list =  $Blog->where("Blog.status=1")->order("cTime desc")->limit($p->firstRow.','.$p->listRows)->select();
            $page = $p->show();
            $this->assign("list", $list);
            $this->assign("page", $page);
            //统计数据
            $Blog = M("Blog");
            $stat = array();
            $stat["beginTime"] = $Blog->min('cTime');
            $stat["blogCount"] = $Blog->where("status=1")->count();
            $stat["readCount"] = $Blog->where("status=1")->sum("readCount");
            $stat["commentCount"] = $Blog->where("status=1")->sum("commentCount");
            $this->assign($stat);
            $this->display();
}

作者: ymywmk   发布时间: 2011-05-08

我之前把它改成
  1. $condition['status']=1;
  2. $count = $Blog->where($condition)->count();
复制代码
这样用的

作者: yuqiguang   发布时间: 2011-05-08