定制 spagination/sprint-framework-pagination-package 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spagination/sprint-framework-pagination-package

Composer 安装命令:

composer require spagination/sprint-framework-pagination-package

包简介

This is a simple and small single class PHP pagination that handles the pagination based on the http request.

README 文档

README

This libary is part of sprint framework packages

Version 1.0.0

Hey! This is a simple and small single class PHP pagination that handles the pagination based on the http request. All properties and methods are statics. The codebase is very small and very easy to understand. So you can use it as a boilerplate for a more complex pagination.

Installation including the file

// Require the class
include 'src\SPagination.php';

Installation using Composer

Just run composer require spagination/sprint-framework-pagination-package Than add the autoloader to your project like this:

// Autoload files using composer
require_once __DIR__ . '/vendor/autoload.php';

// Use this namespace
use sprint\spagination\SPagination;

		// Create an instance of the SPagination class and pass the current page retrieved via http request and the number of results per page as parameters to the constructor
		//First parameter is the page the current page number and second is the limit per page
		$spagination = new SPagination(intval($_GET['page']), 5);

// sql query offset, dynamically generated via the number of results to display per page and the current page number
		//echo $spagination::$offset;

// How to use with the database (This example consider the mysqli, but you can use PDO or any other drivers as well)
// First connect to your database
		$conn   = mysqli_connect("localhost","root","password","database");

//Select the table, use $spagination::$limit to get number of result to return and $spagination::$offset to get the offset dynamically
//To get the total filtered rows use SQL_CALC_FOUND_ROWS command in your query this will ignored the limit and run the query as no limit was informed
		$query  = mysqli_query($conn, "SELECT SQL_CALC_FOUND_ROWS * FROM table ORDER BY id ASC LIMIT ".$spagination::$limit." OFFSET ".$spagination::$offset."");
		$results = array();

// Total filtered results from the sql query
		$total = mysqli_fetch_assoc(mysqli_query($conn, "SELECT FOUND_ROWS() AS totalFiltered"));
		$spagination::$total = $total["totalFiltered"];

//Now fetch the data and store in array
		while($row = mysqli_fetch_assoc($query)){
			$results[] = $row;
		}

// Either show dots in the pagination or not(Accept boolean value)
		$spagination::$dots = true;//false

//debug the database results with the pagination
		echo "<pre>";
			var_dump($results);
		echo "</pre>";
// Build the pagination
		echo $spagination::page();

Custom pagination style

The SPagination uses bootstrap as default style, but you can create your own custom style by defining the classes to the elements. Please refer to the bootstrap documentation for more details, in case you want to use bootstrap for styling your pagination

//This will add custom class to anchor element
//Add general class to the class key and active class to the active key
$spagination::$classes["a"] = array(
	"class" => [""] //default class: ["page-link"]
	"active" => [""] //default class: ["active", "disabled"]
);

//This will add custom class to list item element
//Add general class to the class key and active class to the active key (this is used in case you use list item to style active behaviour)
$spagination::$classes["li"] = array(
	"class" => [""] //default class: ["page-item"]
	"active" => [""]
);

//This will add custom class to unordered list element
//Add general class to the class key
$spagination::$classes["ul"] = array(
	"class" => [""] //default class: ["pagination"]
);

License

This project is licensed under the MIT License. See License File for further information.

Contributors

spagination/sprint-framework-pagination-package 适用场景与选型建议

spagination/sprint-framework-pagination-package 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 06 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 spagination/sprint-framework-pagination-package 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 spagination/sprint-framework-pagination-package 我们能提供哪些服务?
定制开发 / 二次开发

基于 spagination/sprint-framework-pagination-package 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-06-21