search
Homephp教程php手册laypage+laytpl example

laypage加laytpl的使用方法,技术不好,摸索了好久才弄出来。
首先去layer官网下载这两个插件,按照他们的文档引入js
然后我的代码如下:
1:html+jquery<div><!--这是循环获取的数据--></div> <br> <br> //laypage paging<br> Ajaxpage();<br> function Ajaxpage(curr,num){<br> If(!num){<br> ​​​​​Num=5; };<br> var catid=$('#catid').val(); //This is the conditional selection column id<br> var starttime=$('#starttime').val();//This is the conditional filtering start time<br> var endtime=$('#endtime').val();//This is the end time of conditional filtering<br> var title=$('#title').val();//This is the title keyword<br> $.get('{:U("Content/article")}', {<br> Page: curr || 1,num:num,catid:catid,starttime:starttime,endtime:endtime,title:title<br> }, function(data){<br> //This paragraph is the assignment of template rendering of laytpl<br>             var tpl = document.getElementById('arlist').innerHTML; ​ //Define tpl <script id="arlist" type="text/html"></script> <br> Laytpl (tpl). Rreater (data.info.lists, function (html) {// pass the obtained JSON data to it                                                                                                                                                                                                                             document.getElementById('article_list').innerHTML =               //This is to get the data, and then render it into the div with the id of article_list<br>              });<br>                                                                                                                                                                                                                                                                                                                              cont: $('#AjaxPage'), <br>                 pages:data.info.allpage, <br> Skip: true,<br> Skin: '#23c6c8',<br>                 curr: curr || 1,<br> groups: 3,<br>                     jump: function(obj, first){<br>                     if(!first){<br> Ajaxpage(obj.curr,num) <br>                       }<br>                  }<br>              });<br> });<br> }<br> //This is the js template of tpl. I deleted some of the same parts and left the different ones. There is also the use of if tags, but I don’t know how to use the U method here, so I used the jquery method to call it. Some features <br> <script id="arlist" type="text/html"><br /> {{# for(var i=0;i<d.length;i++){ var vo=d[i] }} //This is the for loop in js, just use the tpl template tag {{# } } Contains <br />                                                                                                                                                                                                                                                                                                                                                                             <td style="text-align:center">{{vo.views}}<br />                                                                                                                                                                                                                                           <td style="text-align:center">{{vo.author}}<br /> <td style="text-align:center">{{vo.uptime}}<br /> <td style="text-align:center"><br /> {{# if(vo.status==1){ }} <br /> <a class="label label-info" href="javascript:;" onclick="return ar_status(this,&#039;status_{{vo.id}}_0&#039;);">审核<br /> {{# }else{ }}<br /> <a class="label label-danger" href="javascript:;" onclick="return ar_status(this,&#039;status_{{vo.id}}_1&#039;);">审核<br /> {{# } }}<br /> <br /> <td style="text-align:center"><br /> <div class="btn-group"><br /> <a data-toggle="dropdown" class="label label-info dropdown-toggle">文章操作 <span class="caret"><br /> <ul class="dropdown-menu"><br /> <li><a href="javascript:ar_edit({{vo.id}})" class="font-bold">修改 <br /> <li class="divider"><br /> <li><a href="javascript:ar_del({{vo.id}})" class="J_del">删除<br /> <br /> <br />                                                                                                                                                                                        {{# }; }}<br /> </script><br>2:php<br>//Article list Public function article(){ If($_GET['page']){<br>              $Nowpage = $_GET['page']?$_GET['page']:1; //Get the current page<br>                 $catid=intval($_GET['catid']);//Get conditional filter column id<br>                 $starttime=strtotime($_GET['starttime']);//Conditional filtering start time<br>                  $endtime=strtotime($_GET['endtime']);//Conditional filtering end time<br>                $title=$_GET['title'];//Conditional filtering keywords<br>                 $map="id>0";//Combined query conditions<br>                      if($catid>0){<br>                    $map.=" and catid=".$catid."";                                                             }<br>                 if(!empty($starttime)){<br>                 $map.=" and uptime>=".$starttime." and uptime                if(!empty($endtime)){<br>                  $map.=" and uptime>=".$starttime." and uptime             }<br>                if(!empty($title)){<br>                 $map.=" and title like '%$title%'";<br>             }<br>              $limits = $_GET['num']?$_GET['num']:5; // 5 pieces of data are queried here by default<br>                           // Get the total number of items <br>                $count = M('Article')->where($map)->count();<br> //Calculate total pages<br>              $allpage = ceil($count / $limits);<br>               $allpage = intval($allpage);<br>               $lists = M('Article')->where($map)->page($Nowpage, $limits)-> order('listorder asc')-> select();<br> foreach($lists as $k=>$v){<br>                    $lists[$k]['catname']=catname($v['catid']);//This is the method I wrote to get the current column name<br>                    $lists[$k]['uptime']=friendlyDate($v['uptime']);//This is the method I wrote to get the time<br>             }<br>               $data['allpage']=$allpage;//Return the total number of pages<br>                $data['lists']=$lists;//Query data list<br>               $this->success($data);exit;<br>         }<br>           $cate=M('Category')->order('listorder ASC')->select();<br>           $this->assign('catelist',$cate);<br>           $this->display();<br> }Page made by me

laypage+laytpl example
laypage+laytpl example


If you have any questions, please contact me: QQ 3126620990 My website: http://www.renweinet.net
http://www.hjlog.net


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor