leoshtika/pagination
最新稳定版本:v1.0.1
Composer 安装命令:
composer require leoshtika/pagination
包简介
The simpliest PHP pagination class
README 文档
README
Requirements
- PHP 5.3 or higher
Installation with Composer
- from the command line
composer require leoshtika/pagination
- or updating your composer.json file
{
"require": {
"leoshtika/pagination": "~1.0"
}
}
Usage
Connect to an SQLite database
<?php require_once 'vendor/autoload.php'; use leoshtika\libs\Pagination; use leoshtika\libs\Sqlite; use leoshtika\libs\UserFaker; $sqliteFile = 'demo.sqlite'; // Create a new sqlite db if not exists and load some dummy data. // After the database is created, you don't need this line of code anymore UserFaker::create($sqliteFile, 120); $dbh = Sqlite::connect($sqliteFile); // Get the total number of records $totalRecords = $dbh->query('SELECT count(*) FROM user')->fetch(PDO::FETCH_COLUMN); // Instantiate the Pagination $pagination = new Pagination($_GET['page'], $totalRecords, 10); // Get records using the pagination $sth = $dbh->prepare('SELECT * FROM user LIMIT :offset, :records'); $sth->bindValue(':offset', $pagination->offset(), PDO::PARAM_INT); $sth->bindValue(':records', $pagination->getRecordsPerPage(), PDO::PARAM_INT); $sth->execute(); $users = $sth->fetchAll(PDO::FETCH_OBJ); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Pagination</title> <!-- Bootstrap --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> </head> <body class="container-fluid"> <h1>Pagination!</h1> <table class="table table-bordered table-hover"> <tr> <th>ID</th> <th>Name</th> <th>Email</th> <th>Address</th> <th>Phone</th> </tr> <?php foreach ($users as $user) : ?> <tr> <td><?php echo $user->id; ?></td> <td><?php echo $user->name; ?></td> <td><?php echo $user->email; ?></td> <td><?php echo $user->address; ?></td> <td><?php echo $user->phone; ?></td> </tr> <?php endforeach; ?> </table> <?php echo $pagination->nav(); ?> </body> </html>
Enjoy!
统计信息
- 总下载量: 104
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-03-01