您的位置:首页 > Web前端 > BootStrap

Yii中CLinkPager结合Bootstrap的样式分页

2012-12-16 01:26 567 查看
Controller中:

public function actionIndex()
{

$dataProvider = new CActiveDataProvider('Admin', array(
'criteria' => array(
'order' => 'aid desc',
),
//'pagination' => false,
'pagination' => array(
'pageSize'=> Page::SIZE,
),
));

$this->render('index', array(
'data' => $dataProvider,
));
}


组件Page,为了方便使用把样式的相关属性放到该组件中了。

class Page
{
const SIZE = 15;
static function go($pages)
{
return array(
'header' => '',
'firstPageLabel' => '<<',
'lastPageLabel' => '>>',
'firstPageCssClass' => '',
'lastPageCssClass' => '',
'maxButtonCount' => 8,
'nextPageCssClass' => '',
'previousPageCssClass' => '',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
'selectedPageCssClass' => 'active',
'pages' => $pages,
'internalPageCssClass' => '',
'hiddenPageCssClass' => 'disabled',
'cssFile' => false,
'htmlOptions' => array(
'class' => ''
),
);
}
}


最后是页面呈现部分:

<div class="span10">
<table class="table table-bordered">
<tr>
<th><?php echo Yii::t('zh', 'admin.field.id');?></th>
<th><?php echo Yii::t('zh', 'admin.field.name');?></th>
<th><?php echo Yii::t('zh', 'admin.field.mail');?></th>
<th><?php echo Yii::t('zh', 'admin.field.role');?></th>
<th><?php echo Yii::t('zh', 'admin.field.ip');?></th>
<th><?php echo Yii::t('zh', 'common.field.created');?></th>
<th><?php echo Yii::t('zh', 'common.field.updated');?></th>
</tr>
<?php foreach ($data->getData() as $key => $value): ?>
<tr>
<td><?php echo $value->aid; ?></td>
<td><?php echo $value->name; ?></td>
<td><?php echo $value->mail; ?></td>
<td><?php echo $value->role; ?></td>
<td><?php echo $value->ip; ?></td>
<td><?php echo $value->updated; ?></td>
<td><?php echo $value->created; ?></td>
</tr>
<?php endforeach; ?>
</table>
<div class="pagination">
<?php $this->widget('CLinkPager', Page::go($data->getPagination())); ?>
</div>


主要说个问题,在CLinkPager有一段代码,就是自动加载Css文件的,因为Yii自己默认带了一套css,这里不想使用,那么要设置为false,也就是Page组件当中的cssFile属性。

public function registerClientScript()
{
if($this->cssFile!==false)
self::registerCssFile($this->cssFile);
}


最后的效果图:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: