rogerthomas84 / ohpage
OhPage 是一个用于 PHP 的分页库
1.0.0
2015-09-02 21:07 UTC
Requires
- php: >=5.4.0
Requires (Dev)
- phpunit/phpunit: >=3.7.38
This package is auto-updated.
Last update: 2024-09-16 00:55:44 UTC
README
OhPage 简直就是一个简单的伎俩,实际上是因为我厌倦了计算分页结果集的跳过/限制。
使用 Composer
要使用 Composer 与 OhPage,请在 composer.json
文件中的 require 块中添加依赖项(和版本约束)。
{ "require": { "rogerthomas84/ohpage": "1.0.*" } }
快速开始
<?php $db = new \MongoClient('mongodb://my.database.host:27017'); // Set up your database connection $collection = $db->selectCollection('mydb', 'mycollection'); $perPage = 10; // How many results per page? $currentPage = 1; // The current page $totalResults = $collection->count(); // Get the total from the DB $instance = new PaginateHelper($perPage, $currentPage, $totalResults); $results = $collection->find()->sort( array('createdDate' => -1) )->skip( $instance->getQueryOffset() )->limit( $instance->getQueryLimit() );