首页 > 代码库 > Yii 之分页 + bootstrap

Yii 之分页 + bootstrap

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="http://www.mamicode.com/<?php echo $pages->currentPage <= 0?‘‘:$this->createUrl(‘bank/index‘,array(‘page‘=>$pages->currentPage));?>">&laquo;</a></li>
<?php for($i = 1;$i <= $pages->pageCount;$i++):?>
<li class="<?php echo $pages->currentPage +1 == $i?‘active‘:‘‘; ?>"><a href="http://www.mamicode.com/<?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="http://www.mamicode.com/<?php echo $pages->currentPage+1 >= $pages->pageCount?‘‘:$this->createUrl(‘bank/index‘,array(‘page‘=>$pages->currentPage+2));?>">&raquo;</a></li>
</ul>
</div>
<?php endif;?>