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

原文地址:https://www.cnblogs.com/klj123wan/p/2946258.html