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混合的分页效果

  • 相关阅读:
    【C++ STL】List
    【C++ STL】Deques
    【C++ STL】Vector
    【C++ STL】容器概要
    linux shell读取配置文件
    【C++对象模型】第六章 执行期语意学
    【C++对象模型】第五章 构造、解构、拷贝 语意学
    【C++对象模型】第四章 Function 语意学
    【C++对象模型】第三章 Data语义学
    [翻译]解读CSS中的长度单位
  • 原文地址:https://www.cnblogs.com/klj123wan/p/2946258.html
Copyright © 2011-2022 走看看