宝哥软件园

thinkphp5 layui实现的分页样式示例

编辑:宝哥软件园 来源:互联网 时间:2021-08-19

本文通过一个实例讲述了thinkphp5 layui实现的分页风格。分享给大家参考,如下:

tp5的布局分页风格

1.分页类

路径: think PHP library think paginator driver

Layui.php

?phpnamespace think paginator driver;使用思考分页器类获得扩展了分页器{ /** *上一页按钮* @ param string $ text * @ return string */protected function getPreviousButton($ text='上一页){ if($ this-CurrentPage()=1){ return $ this-getdisabletextwrapper($ text);} $ URL=$ this-URL($ this-CurrentPage()-1);返回$this-getPageLinkWrapper($url,$ text);} /** * 下一页按钮* @ param string $ text * @ return string */protected function get next button($ text='下一页){ if(!$ this-HasMoore){ return $ this-getdisabletextwrapper($ text);} $ URL=$ this-URL($ this-CurrentPage)(1);返回$this-getPageLinkWrapper($url,$ text);} /** * 页码按钮* @返回字符串*/受保护函数getLinks() { if ($this-simple)返回"";$block=[ 'first'=null,' slider'=null,' last '=null];$ side=3;$ window=$ side * 2;if($ this-lastPage $ window 6){ $ block[' first ']=$ this-getUrlRange(1,$ this-lastPage);} else if($ this-CurrentPage=$ window){ $ block[' first ']=$ this-GetURlRange(1,$ window 2);$ block[' last ']=$ this-getUrlRange($ this-lastPage-1,$ this-lastPage);} else if($ this-CurrentPage($ this-LastPage-$ window)){ $ block[' first ']=$ this-GetURlRange(1,2);$ block[' last ']=$ this-getUrlRange($ this-lastPage-($ window 2),$ this-lastPage);} else { $ block[' first ']=$ this-GetURlRange(1,2);$ block[' slider ']=$ this-getUrlRange($ this-currentPage-$ side,$ this-currentPage $ side);$ block[' last ']=$ this-getUrlRange($ this-lastPage-1,$ this-lastPage);} $ html=if(is _ array($ block[' first ']){ $ html .=$ this-geturrlinks($ block[' first ']);} if(is _ array($ block[' slider ']){ $ html .=$ this-GetDots();$html .=$ this-geturrlinks($ block[' slider ']);} if(is _ array($ block[' last ']){ $ html .=$ this-GetDots();$html .=$ this-geturrlinks($ block[' last ']);}返回$ html} /** *渲染分页html * @ return mixed */public function render(){ if($ this-hasPages()){ if($ this-simple){ return sprint f(' ul class='寻呼机%s %s/ul ',$this-getPreviousButton(),$ this-getnext button());} else { return sprintf('%s %s %s ',$this-getPreviousButton(),$this-getLinks(),$ this-getnext button());} } } /** * 生成一个可点击的按钮* * @ param string $ URL * @ param int $ page * @ return string */protected function getAvailablePageWrapper($ URL,$page) { return 'a href=' ' .htmlentities($url)," rel="外部nofollow .$page ./a ';} /** * 生成一个禁用的按钮* * @ param string $ text * @ return string */protected函数getdisabletextwrapper($ text){ return ' a class=' layui-lay page-prev ' ' .$文本/a ';} /** * 生成一个激活的按钮* * @ param string $ text * @ return string */protected function getActivePageWrapper($ text){ return ' span class=' layui-lay page-curr ' em class=' layui-lay page-em '/emem ' .$文本/em/span ';} /** * 生成省略号按钮* * @返回字符串*/受保护函数getDots(){ return $ this-getdisabletextwrapper('.');} /** * 批量生成页码按钮* * @ param array $ URL * @ return string */protected function geturrlinks(array $ URL){ $ html=' ';foreach($ URL as $ page=$ URL){ $ html .=$this-getPageLinkWrapper($url,$ page);}返回$ html} /** *生成普通页码按钮* * @ param string $ URL * @ param int $ page * @ return string */protected function getPageLinkWrapper($ URL,$ page){ if($ page==$ this-currentPage()){ return $ this-getActivePageWrapper($ page);}返回$ this-getAvailablePageWrapper($ URL,$ page);}}2.配置文件

paginate.php

?PHP/* * * @ authr : xxf *日期: 2019/9/2 *时间: 10:24 *//分页配置返回[ 'type'='Layui ',' var_page'='page ',];3.模型查询

公共函数getUserShowList($size=20,$其中=null){ $res=$this -field('id,title,list_order,is_top,create_time,create _ time ')-where($ where)-order([' is _ top '=' desc ',' list_order'='desc ',' id '=' desc '])-paginate($ size);返回$ res}4。模板渲染

div class=' layui-box layui-lay page layui-lay page-molv ' { $ list | raw }/div效果

更多关于框架相关内容感兴趣的读者可查看本站专题: 《ThinkPHP入门教程》 、 《thinkPHP模板操作技巧总结》 、 《ThinkPHP常用方法总结》 、 《codeigniter入门教程》 、 《CI(CodeIgniter)框架进阶教程》 、 《Zend FrameWork框架入门教程》 及《PHP模板技术总结》 。

希望本文所述对大家基于ThinkPHP框架的服务器端编程语言(专业超文本预处理器的缩写)程序设计有所帮助。

更多资讯
游戏推荐
更多+