Example of yii using bootstrap paging style

Source: Internet
Author: User
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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.