Home > php教程 > php手册 > laypage+laytpl example

laypage+laytpl example

WBOY
Release: 2016-08-04 08:56:18
Original
2436 people have browsed it

laypage加laytpl的使用方法,技术不好,摸索了好久才弄出来。
首先去layer官网下载这两个插件,按照他们的文档引入js
然后我的代码如下:
1:html+jquery<div id="article_list"><!--这是循环获取的数据--></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}}</td><br>                                                                                                                                                                                                                                                     <td style="text-align:center">{{vo.author}}</td><br>           <td style="text-align:center">{{vo.uptime}}</td><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;);">审核</a><br>                 {{# }else{ }}<br>                     <a class="label label-danger" href="javascript:;" onclick="return ar_status(this,&#039;status_{{vo.id}}_1&#039;);">审核</a><br>                 {{# } }}<br>            </td><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"></span></a><br>                    <ul class="dropdown-menu"><br>                         <li><a href="javascript:ar_edit({{vo.id}})" class="font-bold">修改</a> </li><br>                         <li class="divider"></li><br>                         <li><a href="javascript:ar_del({{vo.id}})" class="J_del">删除</a></li><br>                      </ul><br>                 </div><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<".$endtime."";                                               }<br />                if(!empty($endtime)){<br />                  $map.=" and uptime>=".$starttime." and uptime<".$endtime."";<br />             }<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


source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template