定制 faurelia/t2-simple-pagination 二次开发

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

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

faurelia/t2-simple-pagination

Composer 安装命令:

composer require faurelia/t2-simple-pagination

包简介

A simple PHP pagination (with Bootstrap 3 example)

README 文档

README

A Simple PHP Pagination library (with Bootstrap 3 example)

Installation

require_once '/path/to/t2-simple-pagination/T2SimplePagination.php';

Usage

Initialize T2SimplePagination providing the 2 required parameters, total and page as well as additional settings.

// get the current page
$page = isset($_GET['p']) ? $_GET['p'] : 1;

// count total data from your record source. ie: DB or a file
$total = DB::count($data);

// set the number of items to display per page
$per_page = 10;

// set the number of page links to display
$range = 7; // IMPORTANT: please use odd numbers ONLY!!!

$pagination = new T2SimplePagination($total, $page, $per_page, $range);

Then extract the records by using the offset and per_page properties.

$query = "SELECT * FROM my_table LIMIT {$pagination->offset}, {$pagination->per_page}"

See the class Properties below for more details.

Page Links

<?php for ($i = $pagination->min_page; $i <= $pagination->max_page; $i++): ?>
<a href="?p=<?php echo $i ?>">
    <?php echo $i ?>
</a>
<?php endfor; ?>

Pager (Next and Prev Links)

<?php if ($pagination->prev_page): ?>
    <a href="?p=<?php echo $pagination->prev_page ?>">Prev</a>
<?php else: ?>
    Prev
<?php endif; ?>

<?php if ($pagination->next_page): ?>
    <a href="?p=<?php echo $pagination->next_page ?>">Next</a>
<?php else: ?>
    Next
<?php endif; ?>

You may want to hide the pagination links when there is only one page, so it is recommended to enclose the above codes inside this if block:

<?php if ($pagination->num_page): ?>
    // pager or page links
<?php endif; ?>

For Bootstrap 3 example, please check the index.php file included in this repository.

Properties

Variables Description
total the total number of records to be paginated
page the current page, default: 1
per_page the number of items to display per page, default: 10
num_page the total number of pages
offset the current record pointer
next_page the next page if page is not equals to num_page
prev_page the previous page if page is not 1
range the number of page links to display, default: 5 (Note: Use ODD numbers only!)
min_page the start page in the page links
max_page the end page in the page links

License

This library is distributed under MIT License. © 2017 Fatima Aurelia

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固