search
HomeBackend DevelopmentPHP TutorialthinkPHP3.2.3 combines Laypage to implement paging function

这篇文章主要介绍了thinkPHP3.2.3结合Laypage实现的分页功能,结合实例形式分析了thinkPHP3.2.3结合Laypage实现分页的model控制器与view视图相关操作技巧,需要的朋友可以参考下

本文实例讲述了thinkPHP3.2.3结合Laypage实现的分页功能。分享给大家供大家参考,具体如下:

控制器

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
  /**
  *@brief 查询
  ****/
  public function index(){
  $choose = I(&#39;choose&#39;,&#39;-6&#39;);
  $c[&#39;easy_hard&#39;] = $choose;
    $type=I(&#39;typeid&#39;,&#39;&#39;);
    $nowpage=I(&#39;page&#39;,1);
    if($type == &#39;&#39;)
    {
      if($choose == -6)
      {
        $totalpage=ceil((D(&#39;data&#39;)->count())/10);
        $infos=D(&#39;data&#39;)->limit(($nowpage-1)*10,10)->select();
      }else{
        $totalpage=ceil((D(&#39;data&#39;)->where($c)->count())/10);
        $infos=D(&#39;data&#39;)->where($c)->limit(($nowpage-1)*10,10)->select();
      }
    }else{
      if($choose == -6)
      {
        $map[&#39;data&#39;] = array(&#39;like&#39;,"%$type%");
        $totalpage=ceil((D(&#39;data&#39;)->where($map)->count())/10);
        $infos=D(&#39;data&#39;)->where($map)->limit(($nowpage-1)*10,10)->select();
      }else{
        $map[&#39;data&#39;] = array(&#39;like&#39;,"%$type%");
        $totalpage=ceil((D(&#39;data&#39;)->where($map)->where($c)->count())/10);
        $infos=D(&#39;data&#39;)->where($map)->where($c)->limit(($nowpage-1)*10,10)->select();
      }
    }
  $this->assign(&#39;type&#39;,$type);
    $this->assign(&#39;choose&#39;,$choose);
    $this->assign("totalpage",$totalpage);
    $this->assign("infos",$infos);
    $this -> display();
  }
}

视图层

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Think Demo</title>
  <script type="text/javascript" src="__PUBLIC__/jquery-1.11.1/jquery.min.js"></script>
  <script type="text/javascript" src="__PUBLIC__/jquery-1.11.1/jquery.js"></script>
  <script type="text/javascript" src="__PUBLIC__/layer/layer.js"></script>
  <script type="text/javascript" src="__PUBLIC__/laypage/laypage.js"></script>
</head>
<body>
<p>
 <select name="" id="slc1" onchange="return choose()">
  <option value="-6" <if condition="$choose eq -6 "> selected </if> >全部</option>
  <option value="0" <if condition="$choose eq 0 "> selected </if> >简单</option>
  <option value="1" <if condition="$choose eq 1 "> selected </if> >一般</option>
 </select>
  <input type="text" value="<if condition="$type neq &#39;&#39; "> {$type} </if>" id="type"><button id="sou">搜索</button>
</p>
<br>
  <table border="1" width="500" height="150" >
        <tr>
          <th>ID</th>
          <th>语言</th>
          <th>难易程度</th>
          <th>操作</th>
        </tr>
        <volist name="infos" id="vo">
        <tr>
          <th>{$vo.id}</th>
          <th>{$vo.data}</th>
          <th>
            <if condition="$vo.easy_hard eq &#39;0&#39;">简单
            <else />一般
            </if>
          </th>
          <th>
            <a href="javascript:;" rel="external nofollow" rel="external nofollow" onclick="return del({$vo.id});">删除</a>
            <a href="javascript:;" rel="external nofollow" rel="external nofollow" onclick="return edit({$vo.id});">修改</a>
          </th>
        </tr>
        </volist>
  </table>
  <p style="margin-top:15px; text-align:center;" id="page11"></p>
  <button onclick="return add_()"> 添加 </button> <br />
<script type="text/javascript">
  function choose()
  {
    var type=$("#type").val();
    var checkValue=$("#slc1").val();
    window.location.href="?typeid=" rel="external nofollow" rel="external nofollow" +type+"&choose="+checkValue;
  }
  $("#sou").bind("click",function(event){
    var type=$("#type").val();//获取假设的搜索条件值
    var checkValue=$("#slc1").val();
    window.location.href="?typeid=" rel="external nofollow" rel="external nofollow" +type+&#39;&choose=&#39;+checkValue;
  });
  $(function(){
      laypage({
        cont: &#39;page11&#39;,
        pages: {$totalpage}, //假设我们获取到的是18(后端计算完总页数后将总页数值传过来,放在这里即可(类似{$totalpage})).
       curr: function(){ //通过url获取当前页,也可以同上(pages)方式获取
         var page = location.search.match(/page=(\d+)/);
            return page ? page[1] : 1;//如果没有页数显示时,默认是第一页
          }(),
          jump: function(e, first){ //触发分页后的回调
            if(!first){ //一定要加此判断,否则初始时会无限刷新
              location.href=setParam("page",e.curr);
            }
          }
      });
  });
  function setParam(param,value){
    var query = location.search.substring(1);
    var p = new RegExp("(^|)" + param + "=([^&]*)(|$)");
    if(p.test(query)){
      //query = query.replace(p,"$1="+value);
      var firstParam=query.split(param)[0];
      var secondParam=query.split(param)[1];
      if(secondParam.indexOf("&")>-1){
        var lastPraam=secondParam.split("&")[1];
        return &#39;?&#39;+firstParam+&#39;&&#39;+param+&#39;=&#39;+value+&#39;&&#39;+lastPraam;
      }else{
        if(firstParam){
          return &#39;?&#39;+firstParam+&#39;&#39;+param+&#39;=&#39;+value;
        }else{
          return &#39;?&#39;+param+&#39;=&#39;+value;
        }
      }
    }else{
      if(query == &#39;&#39;){
        return &#39;?&#39;+param+&#39;=&#39;+value;
      }else{
        return &#39;?&#39;+query+&#39;&&#39;+param+&#39;=&#39;+value;
      }
    }
  }
</script>
</body>
</html>

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

thinkPHP中统计排行与分页显示的功能

thinkphp实现分页显示功能

The above is the detailed content of thinkPHP3.2.3 combines Laypage to implement paging function. For more information, please follow other related articles on the PHP Chinese website!

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
如何在CakePHP中创建自定义分页?如何在CakePHP中创建自定义分页?Jun 04, 2023 am 08:32 AM

CakePHP是一个强大的PHP框架,为开发人员提供了很多有用的工具和功能。其中之一是分页,它可以帮助我们将大量数据分成几页,从而简化浏览和操作。默认情况下,CakePHP提供了一些基本的分页方法,但有时你可能需要创建一些自定义的分页方法。这篇文章将向您展示如何在CakePHP中创建自定义分页。步骤1:创建自定义分页类首先,我们需要创建一个自定义分页类。这个

PHP开发:如何实现表格数据排序和分页功能PHP开发:如何实现表格数据排序和分页功能Sep 20, 2023 am 11:28 AM

PHP开发:如何实现表格数据排序和分页功能在进行Web开发中,处理大量数据是一项常见的任务。对于需要展示大量数据的表格,通常需要实现数据排序和分页功能,以提供良好的用户体验和优化系统性能。本文将介绍如何使用PHP实现表格数据的排序和分页功能,并给出具体的代码示例。排序功能实现在表格中实现排序功能,可以让用户根据不同的字段进行升序或降序排序。以下是一个实现表格

如何使用 JavaScript 实现表格分页功能?如何使用 JavaScript 实现表格分页功能?Oct 20, 2023 pm 06:19 PM

如何使用JavaScript实现表格分页功能?随着互联网的发展,越来越多的网站都会使用表格来展示数据。在一些数据量较大的情况下,需要将数据进行分页展示,以提升用户体验。本文将介绍如何使用JavaScript实现表格分页功能,并提供具体的代码示例。一、HTML结构首先,我们需要准备一个HTML结构来承载表格和分页按钮。我们可以使用&lt;tab

使用JavaScript实现表格数据的分页显示使用JavaScript实现表格数据的分页显示Jun 16, 2023 am 10:00 AM

随着数据的不断增长,表格显示变得更加困难。大多数情况下,表格中的数据量过大,导致表格在加载时变得缓慢,而且用户需要不断地浏览页面才能找到自己想要的数据。本文将介绍如何使用JavaScript实现表格数据的分页显示,让用户更容易找到自己想要的数据。一、动态创建表格为了使分页功能更加可控,需要动态创建表格。在HTML页面中,添加一个类似于下面的table元素。

MyBatis分页插件原理详解MyBatis分页插件原理详解Feb 22, 2024 pm 03:42 PM

MyBatis是一个优秀的持久层框架,它支持基于XML和注解的方式操作数据库,简单易用,同时也提供了丰富的插件机制。其中,分页插件是使用频率较高的插件之一。本文将深入探讨MyBatis分页插件的原理,并结合具体的代码示例进行说明。一、分页插件原理MyBatis本身并不提供原生的分页功能,但可以借助插件来实现分页查询。分页插件的原理主要是通过拦截MyBatis

Vue组件实战:分页组件开发Vue组件实战:分页组件开发Nov 24, 2023 am 08:56 AM

Vue组件实战:分页组件开发介绍在Web应用程序中,分页功能是必不可少的一个组件。一个好的分页组件应该展示简洁明了,功能丰富,而且易于集成和使用。在本文中,我们将介绍如何使用Vue.js框架来开发一个高度可定制化的分页组件。我们将通过代码示例来详细说明如何使用Vue组件开发。技术栈Vue.js2.xJavaScript(ES6)HTML5和CSS3开发环

Vue技术开发中如何实现分页功能Vue技术开发中如何实现分页功能Oct 09, 2023 am 09:06 AM

Vue是一种流行的JavaScript框架,用于构建用户界面。在Vue技术开发中,实现分页功能是常见的需求。本文将介绍如何使用Vue来实现分页功能,并提供具体代码示例。在开始之前,我们需要提前准备一些基本知识。首先,我们需要了解Vue的基本概念和语法。其次,我们需要知道如何使用Vue组件来构建我们的应用程序。开始之前,我们需要在Vue项目中安装一个分页插件,

VUE3开发入门教程:使用组件实现分页VUE3开发入门教程:使用组件实现分页Jun 16, 2023 am 08:48 AM

VUE3开发入门教程:使用组件实现分页分页是一个常见的需求,因为在实际开发中,我们往往需要将大量的数据分成若干页以展示给用户。在VUE3开发中,可以通过使用组件实现分页功能,本文将介绍如何使用组件实现简单的分页功能。1.创建组件首先,我们需要创建一个分页组件,使用“vuecreate”命令创建VUE项目,并在src/components目录下创建Pagin

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

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.

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment