controller
$criteria = new CDbCriteria;
$criteria->order = ‘id asc‘; //这边还可以写其他的sql语句
$count = Bankinfo::model()->count($criteria);
$pages = new CPagination($count);
$pages->pageSize = 1;
$pages->applylimit($criteria);
$bankinfos = Bankinfo::model()->findAll($criteria);
$this->render(‘index‘, array(
‘bankinfos‘ => $bankinfos,
‘pages‘ => $pages,
));
view里
<div class="green-black">
<?php
$this->widget(‘MyLinkPager‘,array(
‘pages‘=>$pages,
));
?>
</div>
view里结合bootstrap //蛋疼在只有 currentPage属性可用
<?php if($pages->pageCount > 1):?>
<div class="page_margin">
<ul class="pagination ">
<li class="<?php echo $pages->currentPage <= 0?‘disabled‘:‘‘; ?>"><a href="<?php echo $pages->currentPage <= 0?‘‘:$this->createUrl(‘bank/index‘,array(‘page‘=>$pages->currentPage));?>">«</a></li>
<?php for($i = 1;$i <= $pages->pageCount;$i++):?>
<li class="<?php echo $pages->currentPage +1 == $i?‘active‘:‘‘; ?>"><a href="<?php echo $this->createUrl(‘bank/index‘,array(‘page‘=>$i));?>"><?php echo $i; ?></a></li>
<?php endfor; ?>
<li class="<?php echo $pages->currentPage+1 >= $pages->pageCount?‘disabled‘:‘‘; ?>"><a href="<?php echo $pages->currentPage+1 >= $pages->pageCount?‘‘:$this->createUrl(‘bank/index‘,array(‘page‘=>$pages->currentPage+2));?>">»</a></li>
</ul>
</div>
<?php endif;?>
Yii 之分页 + bootstrap