Yii2 page-based jump to the instance code of a specific page, yii2 page-based jump to the instance. Yii2 page-based implementation refers to the instance code for redirecting to a specific page. yii2 page-based jump refers to the instance to see the effect first. if you still feel wrong, please refer to how to implement the function! It is not hard to see that the implementation of yii2 page jump to the instance code of a specific page, yii2 page jump to the instance
Let's look at the results first. if you still feel wrong, please refer to how to implement the function!
It is not hard to see that the function for redirecting to a page is based on the extension above linkpager. The paging extension we previously implemented is obviously different, and the previous one is obviously rewritten! Of course, this is not important. let's take a look at the specific implementation of GoLinkPager! The name is a bit lower, not important!
1. create a GoLinkPager class file in the frontend \ components directory.
2. this class inherits yii \ widgets \ LinkPager;, as follows:
namespace frontend\components; use yii\widgets\LinkPager; use yii\helpers\Html; class GoLinkPager extends LinkPager { }
3. Add public $ go = false; // whether to include the jump function. the default value is false.
4. rewrite the renderPageButtons method of the parent linkPager class. for details, refer to the full code below. you can refer to the code implementation in the go section.
<? Phpnamespace frontend \ components; use yii \ widgets \ LinkPager; use yii \ helpers \ Html; class GoLinkPager extends LinkPager {// whether the jump function is included; default value: false public $ go = false; protected function renderPageButtons () {$ pageCount = $ this-> pagination-> getPageCount (); if ($ pageCount <2 & $ this-> hideOnSinglePage) {return '';} $ buttons = []; $ currentPage = $ this-> pagination-> getPage (); // first page $ firstPageLabel = $ This-> firstPageLabel === true? '1': $ this-> firstPageLabel; if ($ firstPageLabel! = False) {$ buttons [] = $ this-> renderPageButton ($ firstPageLabel, 0, $ this-> firstPageCssClass, $ currentPage <= 0, false );} // prev page if ($ this-> prevPageLabel! = False) {if ($ page = $ currentPage-1) <0) {$ page = 0 ;} $ buttons [] = $ this-> renderPageButton ($ this-> prevPageLabel, $ page, $ this-> prevPageCssClass, $ currentPage <= 0, false );} // internal pages list ($ beginPage, $ endPage) = $ this-> getPageRange (); for ($ I = $ beginPage; $ I <= $ endPage; + + $ I) {$ buttons [] = $ this-> renderPageButton ($ I + 1, $ I, null, false, $ I ==$ currentPage );} // next page if ($ This-> nextPageLabel! = False) {if ($ page = $ currentPage + 1) >=$ pageCount-1) {$ page = $ pageCount-1 ;} $ buttons [] = $ this-> renderPageButton ($ this-> nextPageLabel, $ page, $ this-> nextPageCssClass, $ currentPage >=$ pageCount-1, false );} // last page $ lastPageLabel = $ this-> lastPageLabel = true? $ PageCount: $ this-> lastPageLabel; if ($ lastPageLabel! = False) {$ buttons [] = $ this-> renderPageButton ($ lastPageLabel, $ pageCount-1, $ this-> lastPageCssClass, $ currentPage >=$ pageCount-1, false);} // go if ($ this-> go) {$ goPage = $ currentPage + 2; $ goHtml = <
{$ PageCount} pages in total to
Page OK
GoHtml; $ buttons [] = $ goHtml; $ pageLink = $ this-> pagination-> createUrl (false); $ goJs = <
Options );}}
The specific usage is as follows:
<?= GoLinkPager::widget([ 'pagination' => $pages, 'go' => true, ]); ?>
We can see that it is convenient for thieves to use it! Add an attribute go to true.
In the full version of the code, go html js can be modified as needed!
The above content is the example code for yii2 paging to jump to a specific page. I hope it will help you!
Refer first to the results. if you still feel wrong, please refer to how to implement the function! It is not difficult to see that I...