This article mainly introduces the example of using bootstrap pagination style in yii. I think this is a good example. I will share it with you and give you a reference. Let's take a look at Bootstrap as an open-source front-end development toolkit launched by Twitter. It was developed by Twitter designer Mark Otto and Jacob Thornton. it is a CSS/HTML framework. Bootstrap provides elegant HTML and CSS specifications, which are written by the dynamic CSS language Less. Since its launch, Bootstrap has become a popular open-source project on GitHub. it is used by Breaking News of NASA's MSNBC (Microsoft National Broadcasting Corporation.
This article describes how yii uses the bootstrap pagination style. For more information, see.
Yii comes with paging classes and page styles. but how can I use bootstrap paging styles without modifying yii in yii + bootstrap.
This article introduces a very simple method. to apply the bootstrap style to yii pages, we mainly rely on the two attributes htmlOptions and selectedPageCssClass in yii CLinkPager.
Controller Sample code
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));}
The above code implements yii paging and uploads the $ pager paging object to the view. let's take a look at the View code.
View code
Widget ('clinkpager', array ('header' => '', 'firstpagelabel '=> 'homepage', 'lastpagelabel '=> 'Last page ', 'prevpagelabel '=> 'preg', 'nextpagelabel' => 'next page', 'page' => $ pager, 'maxbuttoncount' => 8, 'cssfile' => false, 'htmlopexception' => array ("class" => "pagination"), 'selectedpagecssclass '=> "active");?>
The preceding View code should pay attention to the following points:
1. the page must be in
Li
2. the htmlOptions option is required. it specifies the class name of paging p generated by yii. here we use the class name of bootstrap.
3. the selectedPageCssClass option specifies a large number of currently selected pages. here we use the active
4. In addition, you also need to set cssFile to false without loading the pagination css style file.
Refer to the page code provided on the bootstrap official website, as shown in
The above is all the content of this article. I hope it will help you learn and support PHP.
For more articles about the use of bootstrap pagination for yii instances, refer to PHP!