Cdbcriteria This is the use of class packages, which are designed to be used by YII to handle similar classification functions.
And we use the YII framework and then call this method will play a multiplier effect, we will find that the use of this can save a lot of time. Allows you to use PHP in a high-speed paging function.
Also use a class package is cpagination, the detailed element attributes are not explained, can directly connect to the past to see the API
The first step:
Add a bit of code to the controller:
$criteria = new Cdbcriteria (); $criteria->alias = ' post ';//To query the alias of the table $criteria->order = ' createtime desc '; The length of the list time shown in the article $criteria->condition = ' type_id=:type_id ';//The criteria for querying records. Same as the use of Find () in yii $criteria->params = Array (': type_id ' = $id); $criteria->distinct = ";//is the distinct value setting in SQL query statement, generally use less $criteria->group =";//is the value setting of group in SQL query statement, generally use less $criteria->select = ' * ';//sql the SELECT statement in the query statement is worth setting, the default is that * $count = Post::model ()->count ($criteria);// By setting the above query statement, and then querying out the number of records that meet the above criteria $pages = new Cpagination ($count);//Infer how many pages the above record can display//cpagination render relevant information to the page number. When data needs to be rendered to multiple pages, we may use cpagination to render information, such as total item count, page Size,current page, and so on. This information is passed to the pagers Render paging button or link.$pages->pagesize = 1;//The record of each page shows how many $pages->applylimit ($criteria); $post = Post::model ()->findall ($criteria);
Step Two:
Just add a bit of code to the views display, you can show the effect.
<div class= "Pagenav" id= "Pagenavi" ><span> co-owned <?php Echo $pages->itemcount;?> page </span> <?php$this->widget (' Clinkpager ', array ( ' header ' = = ', ' firstpagelabel ' = ' home ', ' Lastpagelabel ' + ' last ', ' prevpagelabel ' = ' prev ', ' Nextpagelabel ' and ' Next ', ' pages ' and $pages, ' maxbuttoncount ' = 8 ));?></div>
Assuming that the bootstrap framework is used, the following code can be used. It will show the effect of Bootstrap.
<!--//Use bootstrap style paging--><?php $this->widget (' Clinkpager ', Array ( ' pages ' = $pages, ' Header ' =>false, ' htmloptions ' =>array (' class ' = ' pagination pull-right '), ' Selectedpagecssclass ' = ' active ', ' hiddenpagecssclass ' = ' disabled ', ' firstpagelabel ' = ' home ', ' lastpagelabel ' = > ' last ', ' prevpagelabel ' = ' «', ' nextpagelabel ' = '» ', ' maxbuttoncount ' =>5, ' Cssfile ' =>false, ' firstpagecssclass ' = ' previous ', ' lastpagecssclass ' = ' next ', ); >
The following are the effects of bootstrap:
Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.
Yii uses the paging function