thinkphp分页

//分页函数,可放在公共函数中
function getPage($count,$num){
    $Page       = new \Think\Page($count,$num);// 实例化分页类 传入总记录数和每页显示的记录数(25)
    $Page->setConfig('prev','上一页');
    $Page->setConfig('next','下一页');
    $Page->setConfig('first','首页');
    $Page->setConfig('last','尾页');
    $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
    $Page->rollPage=5;
    $Page->lastSuffix=false;

    $show       = $Page->show();// 分页显示输出
    // return $show;
    return array(
        'show' => $show,
        'firstRow' => $Page->firstRow,
        'listRows' => $Page->listRows,
    );
}

public function index(){
    $news = M('news');
    $count = $news->count();
    $pageInfo = getPage($count,100);
    $show = $pageInfo['show'];
    $vir = $news->order('news_id desc')->limit($pageInfo['firstRow'].','.$pageInfo['listRows'])->select();
    $data = array(
        'vir' => $vir,
        'show' => $show
    );

    $this->assign($data);
    $this->display();

}

上一篇:Powershell管理系列(三)2012 AD域用户UPN名称还原


下一篇:ZAO 背后的深度学习算法原理浅析