Bootstrap是Twitter推出的一个开源的用于前端开发的工具包。它由Twitter的设计师Mark Otto和Jacob Thornton合作开发,是一个CSS/HTML框架。Bootstrap提供了优雅的HTML和CSS规范,它即是由动态CSS语言Less写成。Bootstrap一经推出后颇受欢迎,一直是GitHub上的热门开源项目,包括NASA的MSNBC(微软全国广播公司)的Breaking News都使用了该项目。

本文为大家介绍的是yii使用bootstrap分页样式方法,感兴趣的同学参考下。

yii自带了分页类和页面样式,但如果是yii+bootstrap开发的项目如何在不修改yii的情况下使用bootstrap分页样式呢。

本文就为大家介绍一种非常简单的方式,想在yii的分页中套用bootstrap样式主要依赖yii CLinkPager中的二个属性htmlOptions和selectedPageCssClass

控制器示例代码

public function actionIndex()
{
$cid = intval($_GET['cid']); $criteria = new CDbCriteria();
$criteria->addCondition("t.status=1");
$criteria->addCondition("cid='$cid'");
$criteria->order="t.time desc";
$count = Article::model()->count($criteria);
$pager = new CPagination($count);
$pager->pageSize=20;
$pager->applyLimit($criteria);
$lists = Article::model()->findAll($criteria); $this->render('index',array('lists'=>$lists,"pager"=>$pager));
}

上面 代码实现了yii分页,并把$pager分页对象传到视图里,我们再来看一下视图代码

视图代码

<nav>
<?php
$this->widget('CLinkPager',array(
'header'=>'',
'firstPageLabel' => '首页',
'lastPageLabel' => '末页',
'prevPageLabel' => '上一页',
'nextPageLabel' => '下一页',
'pages' => $pager,
'maxButtonCount'=>8,
'cssFile'=>false,
'htmlOptions' =>array("class"=>"pagination"),
'selectedPageCssClass'=>"active"
)
);
?>
</nav>

上面的视图代码要注意以下几个点

1.分页必须在<nav>里

2,htmlOptions选项是必须的,他指定了yii生成的分页div的class名称,在这里我们使用bootstrap的class名

3,selectedPageCssClass选项指定了当前选中页的样多,在这里我们使用bootstrap的active

4.另外还需要把cssFile设为false,不加载分页css样式文件

参考bootstrap官网提供的分页代码,如下图

最终实现的效果图

yii使用bootstrap分页样式的更多相关文章

  1. bootstrap 分页样式代码

    bootstrap 分页样式代码,废话不多说,直接上源码 <!DOCTYPE html> <html> <head> <title>Bootstrap ...

  2. 打造简单实用的Thinkphp分页样式(Bootstrap版本)

    先吐槽一下ThinkPHP3.1版的分页样式,虽然看起来也很简单大方,但是所有的页码全是使用简单的数字,之间的空隙比较小,不大容易点,还有那个“前5页”和“后5页”显得有点多余,因为点击当前显示第一页 ...

  3. bootstrap导航条+模态对话框+分页样式

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  4. Bootstrap -- 导航栏样式、分页样式、标签样式、徽章样式

    Bootstrap -- 导航栏样式.分页样式.标签样式.徽章样式 1. 使用图标的导航栏 使用导航栏样式: <!DOCTYPE html> <html> <head&g ...

  5. Bootstrap分页插件:bootstrap-paginator

    今天和大家分享一个Bootstrap的分页插件:bootstrap-paginator. 插件地址: https://github.com/lyonlai/bootstrap-paginator 先看 ...

  6. DataTables ajax + bootstrap 分页/搜索/排序/常见问题

    最近学校的网站建设需要,尝试使用了下Jquery dataTables控件,接触过C#的人都知道,C#中也含有一个DataTable,但它和我们今天讨论的东西无关 我使用的是官网最新的DataTabl ...

  7. Bootstrap分页插件ajax返回数据,工具类的编写

    使用Bootstrap分页插件时,需要返回指定的参数,这样Bootstrap才能够识别 需要引入的css: <!-- boostrap table --> <link href=&q ...

  8. 【thinkphp5】 分页样式修改

    1 找到文件:/thinkphp/library/think/paginator/driver/Bootstrap.php <?php // +------------------------- ...

  9. [ Laravel 5.6 文档 ]laravel数据库操作分页(自定义分页实现和自定义分页样式)

    简介 在其他框架中,分页可能是件非常痛苦的事,Laravel 让这件事变得简单.易于上手.Laravel 的分页器与查询构建器和 Eloquent ORM 集成在一起,并开箱提供方便的.易于使用的.基 ...

随机推荐

  1. 素材网站——mokuge

  2. sql_autoload_register()函数

    复习__autoload的时候,看到了spl_autoload_register()这个函数.但是一下子没有弄明白,通过查资料我算是弄明白了. 1.__autoload()    ——    自动加载 ...

  3. verilog 1995 VS 2001 part1模块声明的扩展

    1.模块声明的扩展 (1)端口声明(input/output/inout)同数据类型声明(reg /wire)放在同一语句中. (2)ANSI C风格的端口声明可以用于module/task/func ...

  4. LeetCode(23)Merge k Sorted Lists

    题目 Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity ...

  5. hdu 6318

    Long long ago, there was an integer sequence a.Tonyfang think this sequence is messy, so he will cou ...

  6. selenium2中TestNG相关解释

    testNg官网:http://testng.org/doc/documentation-main.html 新建testNG class的时候,同时也新建了一个TestNG.xml的文件. 此xml ...

  7. python基础学习笔记——面向对象初识

    面向对象初识 python中一切皆对象. 类有两种: 新式类:在py3中所有类都是新式类 经典类:在py2中只有类本身继承了object类才叫做新式类,默认是经典类 class Person: cou ...

  8. 更改activity切换方式

    overridePendingTransition(enterAnim, exitAnim); Intent intent =new Intent(this,item2.class); startAc ...

  9. Linux inode 之我见

    Linux硬盘组织方式为:引导区.超级块(superblock),索引结点(inode),数据块(datablock),目录块(diredtory block).其中超级块中包含了关于该硬盘或分区上的 ...

  10. UTV - URL Tag Validation

    What`s UTV 1.URL Tag Validation 2.Special format of URL for preventing unauthorized usage and access ...