Yii中CLinkPager结合Bootstrap的样式分页
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);
}最后的效果图:

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。
- 上一篇: php 正则判断是否为数字
- 下一篇: 关于系统架构,项目设计案例(一):抽奖系统概率设计
