yii2 分页
$criteria = new CDbCriteria();
$common=Yii::app()->db->createCommand();
$common->select("count(*)");
$common->from('asd_user');
$pages = new CPagination($common->queryScalar());
$pages->pageSize = 2;
$common2=Yii::app()->db->createCommand();
$common2->select("*");
$common2->from('asd_user');
$common2->limit($pages->pageSize);
$common2->offset($pages->currentPage*$pages->pageSize);
$data=$common2->queryAll();
echo '总页数='.$pages->getPageCount().'</br>';
echo '总共条数='.$pages->getItemCount().'</br>';
echo '当前也数='.($pages->getCurrentPage()+1).'</br>';
$this->renderPartial('ceshi',array('data'=>$data,'pages'=>$pages))
<?php
$this->widget('CBootstraplinkPager', array(
'pages' => $pages,
// 'selectedPageCssClass' => 'active', //当前页的class
// 'hiddenPageCssClass' => 'disabled', //禁用页的class
// 'header' => '', //分页前显示的内容
// 'maxButtonCount' => 10, //显示分页数量
// 'htmlOptions' => array('class' => ''),
// 'firstPageLabel' => '首页',
// 'nextPageLabel' => '下一页',
// 'prevPageLabel' => '上一页',
// 'lastPageLabel' => '末页',
)
);
?>