Yii uses the bootstrap paging style instance, yiibootstrap
Bootstrap is 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
<Nav> <? Php $ this-> 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");?> </Nav>
The preceding view code should pay attention to the following points:
1. The page must be in <nav>
2. The htmlOptions option is required. It specifies the class Name of the paging div 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
Final Implementation
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.