Home  >  Article  >  Backend Development  >  Code example of how to increase the total number of pages and records in LinkPager in yii2

Code example of how to increase the total number of pages and records in LinkPager in yii2

黄舟
黄舟Original
2017-09-09 09:20:431874browse

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([

  &#39;pagination&#39; => $pages,

  &#39;firstPageLabel&#39;=>"首页",

  &#39;prevPageLabel&#39;=>&#39;上一页&#39;,

  &#39;nextPageLabel&#39;=>&#39;下一页&#39;,

  &#39;lastPageLabel&#39;=>&#39;末页&#39;

]);?>

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn