zoukankan      html  css  js  c++  java
  • yii dwz 分页功能

    利用dwz分页

    controller中设置页面数量:DEFAULT_PAGE_SIZE

    const DEFAULT_PAGE_SIZE = 20;
    const DEFAULT_PAGE_NUM = 0;

    public function actionIndex() {

    $numPerPage = self::DEFAULT_PAGE_SIZE;

    if (isset($_POST['pageNum'])) {
    $pageNum = ($_POST['pageNum'])-1;
    } else {
    $pageNum = self::DEFAULT_PAGE_NUM;
    }
    $user_model = new user();
    $users = $user_model->getUsers($pageNum, $numPerPage);
    $this->render('index', array('users'=> $users, 'pages'=>$user_model->getPages(), 'count'=>$user_model->getCount()));
    }

    model 中数据库的查询

    public function getUsers($pageNum, $numPerPage) {
    $result = $this->db->createCommand()->select('count(*)')->from($this->table_name)->queryColumn();
    $this->count = $result[0];
    $this->pages = new CPagination($this->count);
    $this->pages->pageSize = $numPerPage;
    $this->pages->currentpage = $pageNum;
    $result = $this->db->createCommand()->select('*')->from($this->table_name)->order('id desc')->limit($numPerPage)->offset($this->pages->getOffset())->queryAll();
    return empty($result) ? array() : $result;
    }

    view中页面的显示

    <div class="panelBar">
    <div class="pages">
    <span>显示</span> <span>20条/页,共<?php echo $count?>条</span>
    </div>

    <div class="pagination" targetType="navTab" totalCount="<?php echo $count?>" numPerPage="20" pageNumShown="10" currentPage="<?php echo $pages->currentPage+1;?>"></div>

    </div>

    上面就是yii和dwz混合的分页效果

  • 相关阅读:
    天梯赛
    CF#715 div2
    「Solution」C++ 循环结构 阶乘问题
    「ASCII Art」字符画黑人抬棺
    「Solution」P5759 [NOI1997]竞赛排名
    miller_rabin判断质数logn
    Contest 2050 and Codeforces Round #718 (Div. 1 + Div. 2) A B C 题解
    Codeforces Round #717 (Div. 2) A B C 题解
    redis php常用操作
    php7 操作MongoDB
  • 原文地址:https://www.cnblogs.com/klj123wan/p/2946258.html
Copyright © 2011-2022 走看看