分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

再看thinkphp5分页类使用

发布时间:2023-11-01 15:52责任编辑:沈小雨关键词:thinkphp

之前使用tp5的分页paginate类时只用到了第一个参数,也就是每页显示多少行

今天又仔细看了下手册和paginate类,发现paginate可传入的参数有很多,可以满足更多需求

比如可以指定分页的数据,可以使用重写的分页类等。。。

下面是tp5.1的分页类

 /** ????* 分页查询 ????* @access public ????* @param ?int|array $listRows 每页数量 数组表示配置参数 ????* @param ?int|bool ?$simple ??是否简洁模式或者总记录数 ????* @param ?array ????$config ??配置参数 ????* ???????????????????????????page:当前页, ????* ???????????????????????????path:url路径, ????* ???????????????????????????query:url额外参数, ????* ???????????????????????????fragment:url锚点, ????* ???????????????????????????var_page:分页变量, ????* ???????????????????????????list_rows:每页数量 ????* ???????????????????????????type:分页类名 ????* @return \think\Paginator ????* @throws DbException ????*/ ???public function paginate($listRows = null, $simple = false, $config = []) ???{ ???????if (is_int($simple)) { ???????????$total ?= $simple; ???????????$simple = false; ???????} ???????$paginate = Container::get(‘config‘)->pull(‘paginate‘); ???????if (is_array($listRows)) { ???????????$config ??= array_merge($paginate, $listRows); ???????????$listRows = $config[‘list_rows‘]; ???????} else { ???????????$config ??= array_merge($paginate, $config); ???????????$listRows = $listRows ?: $config[‘list_rows‘]; ???????} ???????/** @var Paginator $class */ ???????$class = false !== strpos($config[‘type‘], ‘\\‘) ? $config[‘type‘] : ‘\\think\\paginator\\driver\\‘ . ucwords($config[‘type‘]); ???????$page ?= isset($config[‘page‘]) ? (int) $config[‘page‘] : call_user_func([ ???????????$class, ???????????‘getCurrentPage‘, ???????], $config[‘var_page‘]); ???????$page = $page < 1 ? 1 : $page; ???????$config[‘path‘] = isset($config[‘path‘]) ? $config[‘path‘] : call_user_func([$class, ‘getCurrentPath‘]); ???????if (!isset($total) && !$simple) { ???????????$options = $this->getOptions(); ???????????unset($this->options[‘order‘], $this->options[‘limit‘], $this->options[‘page‘], $this->options[‘field‘]); ???????????$bind ???= $this->bind; ???????????$total ??= $this->count(); ???????????$results = $this->options($options)->bind($bind)->page($page, $listRows)->select(); ???????} elseif ($simple) { ???????????$results = $this->limit(($page - 1) * $listRows, $listRows + 1)->select(); ???????????$total ??= null; ???????} else { ???????????$results = $this->page($page, $listRows)->select(); ???????} ???????$this->removeOption(‘limit‘); ???????$this->removeOption(‘page‘); ???????return $class::make($results, $listRows, $page, $total, $simple, $config); ???}

再看thinkphp5分页类使用

原文地址:https://www.cnblogs.com/jcydd/p/10804232.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved