<?php
namespace JasonGrimes;
class Paginator
{
const NUM_PLACEHOLDER = '(:num)';
protected $totalItems;
protected $numPages;
protected $itemsPerPage;
protected $currentPage;
protected $urlPattern;
protected $maxPagesToShow = 10;
protected $previousText = 'Previous';
protected $nextText = 'Next';
/**
* @param int $totalItems The total number of items.
* @param int $itemsPerPage The number of items per page.
* @param int $currentPage The current page number.
* @param string $urlPattern A URL for each page, with (:num) as a placeholder for the page number. Ex. '/foo/page/(:num)'
*/
public function __construct($totalItems, $itemsPerPage, $currentPage, $urlPattern = '')
{
$this->totalItems = $totalItems;
$this->itemsPerPage = $itemsPerPage;
$this->currentPage = $currentPage;
$this->urlPattern = $urlPattern;
$this->updateNumPages();
}函數1:根據總頁數,當前頁,和頁分組及url產生分頁導航,分頁函數參數列表(有多少頁,當前頁,每頁多少個 ,鏈接地址)。函數2:依記錄數,頁列清數,$page,目前頁;$row_num記錄總數;$pagesize:每頁記錄數;$url記錄頁。