Home > Article > Backend Development > Code example of how to increase the total number of pages and records in LinkPager in yii2
This article mainly introduces the example of LinkPager in php to increase the total number of pages and total records. It has certain reference value. Those who are interested can learn about it.
This article introduces the LinkPager in php to increase the total number of pages. Number and total number of records, share it with everyone, and leave a note for yourself
Project path vendor\yiisoft\yii2\widgets\LinkPager.php
Add ## to the renderPageButtons method
#
/****增加总页数***/ $buttons[] = Html::tag('li', Html::tag("span", '共'.$this->pagination->getPageCount().'页'), ['class'=>$this->pageCssClass]); /****增加总条数***/ $buttons[] = Html::tag('li', Html::tag("span", '共'.$this->pagination->totalCount.'条记录'), ['class'=>$this->pageCssClass]);Methods in models
use yii\data\Pagination; $page = [ 'PageSize'=>10,//每页的数量 'totalCount'=>(int) $obj->count(),//统计筛选后的数量 ]; $list=$obj->offset($page->offset) ->limit($page->limit) ->all(); return [ 'list'=>$list, 'page'=>$page ];Usage method (view)
<?php use yii\widgets\LinkPager; ?> <?= LinkPager::widget([ 'pagination' => $pages, 'firstPageLabel'=>"首页", 'prevPageLabel'=>'上一页', 'nextPageLabel'=>'下一页', 'lastPageLabel'=>'末页' ]);?>
The above is the detailed content of Code example of how to increase the total number of pages and records in LinkPager in yii2. For more information, please follow other related articles on the PHP Chinese website!