Thinkphp下实现分页
$count=M('wish')->count(); $page = new \Think\Page($count,5);//传入总页数和每页要得到的记录 $this->wish = M('wish')->order('time')->limit($page->firstRow.','.$page->listRows)->select();//从第一条开始,每次查询5条 $page->setConfig('theme', "%HEADER% 当前第%NOW_PAGE%页 %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END%");//分页的要得到的属性,可以自由给出 $this->page=$page->show(); //调用show方法显示并分配到模板 $this->display();
实例化一个分页类,可以用p($page)来查看$page的属性,page,大小写问题,api上用的大写,自己一般用小写,真是浪费我时候
Think\Page Object ( [firstRow] => 0 [listRows] => 5 [parameter] => Array ( ) [totalRows] => 17 [totalPages] => [rollPage] => 11 [lastSuffix] => 1 [p:Think\Page:private] => p [url:Think\Page:private] => [nowPage:Think\Page:private] => 1 [config:Think\Page:private] => Array ( [header] => <span class="rows">共 %TOTAL_ROW% 条记录</span> [prev] => << [next] => >> [first] => 1... [last] => ...%TOTAL_PAGE% [theme] => %HEADER% 当前第%NOW_PAGE%页 %FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% ) )
这样可以实现一个分页