Home > Article > Backend Development > The implementation of yii2 paging extension jumps to a specific page, yii2 paging extension jumps_PHP tutorial
Author: Bai Lang Source: http://www.manks.top/yii2_linkpager_widget. html The copyright of this article belongs to the author, and you are welcome to reprint it. However, this statement must be retained without the author's consent, and a link to the original text must be provided in an obvious position on the article page. Otherwise, we reserve the right to pursue legal liability.
Let’s take a look at the effect in the picture above. Although the style is a bit ugly, it doesn’t matter. I believe that when you get the code, what you pay more attention to is how this function is implemented!
(See original text for picture)
It is not difficult to see from the picture above that the function we developed to jump to a certain page is based on the extension on linkpager. This paging extension we implemented before is obviously different. 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, so it doesn’t matter!
1. Create a new GoLinkPager class file in the frontendcomponents directory
2. This class inherits yiiwidgetsLinkPager;, as follows:
<span>namespace frontend\components; </span><span>use</span><span> yii\widgets\LinkPager; </span><span>use</span><span> yii\helpers\Html; </span><span>class</span> GoLinkPager <span>extends</span><span> LinkPager { }</span>
3. Add attribute public $go = false; //Whether the jump function is included. The default is false
4. Rewrite the renderPageButtons method of the parent class linkPager. For details, refer directly to the full version of the code below. You can mainly look at the code implementation of the go part.
[Considering that most domestic websites currently collect articles very frequently, and some even do not indicate the source of the original article, the original author hopes that readers can check the original article to prevent any problems and not update all articles to avoid misleading! ]
Continue reading