Home  >  Article  >  php教程  >  yii2分页扩展之实现跳转到具体某页

yii2分页扩展之实现跳转到具体某页

WBOY
WBOYOriginal
2016-06-10 15:03:081046browse

作者:白狼 出处:http://www.manks.top/yii2_linkpager_widget.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

先上图看效果,样式虽然有点丑,这都不重要,我相信拿到代码的你们更注重的是这功能怎么实现的!

(图片见原文)

从上图中不难看出,我们制定跳转到某页的功能是基于linkpager之上的扩展,这根我们之前实现的分页扩展明显不同,之前的明显就是重写了!当然,这都不重要,我们看看GoLinkPager的具体实现!名字起的有点lower,不重要!
1、在frontend\components目录新建GoLinkPager类文件

2、该类继承yii\widgets\LinkPager;,如下:

<span style="color: #000000;">namespace frontend\components; 
</span><span style="color: #0000ff;">use</span><span style="color: #000000;"> yii\widgets\LinkPager; 
</span><span style="color: #0000ff;">use</span><span style="color: #000000;"> yii\helpers\Html; 
</span><span style="color: #0000ff;">class</span> GoLinkPager <span style="color: #0000ff;">extends</span><span style="color: #000000;"> LinkPager 
{ 
}</span>

 

3、添加属性public $go = false; //是否包含跳转功能跳转 默认false

4、重写父类linkPager的renderPageButtons方法,具体直接参考下面完整版代码,可主要看go部分的代码实现。

[考虑目前国内网站大部分采集文章十分频繁,更有甚者不注明原文出处,原作者更希望看客们查看原文,以防有任何问题不能更新所有文章,避免误导!]

继续阅读

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