承接 minmb/php-paginator 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

minmb/php-paginator

Composer 安装命令:

composer require minmb/php-paginator

包简介

An extensible PHP pagination library

README 文档

README

PHP-Paginator is a simple library. It's inspired by the Django's pagination and this tutorial, following the best practices from the Symfony2 community.

Installation

First clone the repository with the dependencies:

git clone git://github.com/minmb/PHP-Paginator.git
cd PHP-Paginator
git submodule init
git submodule update

Documentation

The goal of PHP-Paginator is to be as long as possible independent from the database engine and ORM used by the end user, in fact, you can use it even for paginate data fetched from other sources rather than a database. In order to have this flexibility PHP-Paginator can't be used directly in your project but with a minimal setup you will be ready to go.

The library is composed by four types of objects:

  1. A Paginator object: The object that manages the pagination
  2. A Page object: The representation as a page of data
  3. A Paginated object: This object is the cornerstone of the library, and the one you will to use must. It is passed to the paginator and is responsible of fetching the data from the source you want
  4. A Layout object: This object is responsible of managing the representation (as html or any format you want) of the navigation links of the paginator.

PHP-Paginator has a Paginator, Page, SimpleLayout and PaginatedArray out of the box:

<?php
require_once 'path/to/lib/PHP-Paginator/autoload.php';

use Paginator;

$paginatedItems = new Paginator\PaginatedArray(array(1, 2, 3, 4, 5));
$paginator = new Paginator\Paginator($paginatedItems);

$page = $paginator->getPage(1);

foreach($page as $item) {
	printf('Item: %s', $item);
}

PaginatedArray is a class implementing the interface Paginator\PaginatedInterface. In order to create your own Paginated components, you need to implement the two methods of this interface which are:

count()
getSlice($length, $offset)

count() should return an integer representing the length of the dataset your working with getSlice($length, $offset) receives a length and an offset and should return a list/array of elements of your dataset.

Here's an example. In my custom project I have created a ProductsPaginatedQuery class that connects to my database:

<?php

require_once 'path/to/lib/PHP-Paginator/autoload.php';

use Paginator;


class ProductsPaginatedQuery implements Paginator\PaginatedInterface
{
	public function count()
	{
		return MyDBHandler::query("select count(*) from products");
	}

	public function get_slice($length, $offset)
	{
		return MyDBHandler::query("select * from products limit $length offset $offset");
	}
}

$paginatedItems = new ProductsPaginatedQuery();
$paginator = new Paginator\Paginator($paginatedItems);

$page = $paginator->getPage(1);

foreach($page as $item) {
	printf('Item: %s', $item);
}

As you see, you can make your paginated class as complicated and custom as you want, PHP-Paginator doesn't get in your way.

Compatibility

PHP-Paginator works with PHP 5.3.2 or later.

License

PHP-Paginator is licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-11-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固