anzubko/swf-paginator

最简单的分页框架计算器

1.0.0 2024-09-22 09:12 UTC

This package is auto-updated.

Last update: 2024-09-22 09:13:31 UTC


README

此类用于在某种数据上组织逐页导航。主要用于在网站上构建逐页导航面板。

安装

composer require anzubko/swf-paginator

用法

use SWF\Paginator;

$p = new Paginator(
    $totalEntries,   // total number of entries (>=1)
    $entriesPerPage, // number of entries per page (>=1)
    $pagesPerSet,    // number of pages per set (>=1)
    $currentPage,    // current number of page
);

// Get some property directly
$p->totalEntries;

// Or by method call
$p->getTotalEntries();

属性

切片参数

  • $p->startOfSlice - 切片起始位置(>=0)

  • $p->endOfSlice - 切片结束位置(>=0)

  • $p->lengthOfSlice - 切片长度(>=1)

统计数据

  • $p->totalEntries - 条目总数(>=1)(从参数复制)

  • $p->entriesPerPage - 每页条目数(>=1)(从参数复制)

  • $p->pagesPerSet - 每套页数(>=1)(从参数复制)

页面控制

  • $p->totalPages - 总页数(>=1)

  • $p->currentPage - 当前页码(>=1)(从参数复制并修正)

  • $p->prevPage - 前一页码(>=1或null)

  • $p->nextPage - 下一页码(>=1或null)

页面套控制

  • $p->startOfSet - 当前套起始位置(>=1)

  • $p->endOfSet - 当前套结束位置(>=1)

  • $p->pageOfPrevSet - 前一套最近页码(>=1或null)

  • $p->pageOfNextSet - 下一套最近页码(>=1或null)

  • $p->numbersOfSet - 套数(数组中一个或多个大于等于1的数字)

示例

简单

             <-- previous page | next page -->
                   /                   \
           $p->prevPage            $p->nextPage

高级

                    $p->currentPage
                            |
        $p->prevPage        |           $p->nextPage
                \           |                /
        <<       <       6 [7] 8 9 10       >       >>
        /               /           \                \
$p->pageOfPrevSet      /             \    $p->pageOfNextSet
                      /               \
            $p->startOfSet       $p->endOfSet
                     |                |
                    [ $p->numbersOfSet ]

统计数据

                $p->totalPages
               /   $p->totalEntries
Total pages: 20   /
Total records: 200
Shown from 61 to 70 records
             \     \
              \     $p->startOfSlice + 1
               $p->endOfSlice + 1

注意

  • 检查是否需要显示导航面板的最简单方法,是检查$p->totalPages属性。如果这个属性大于1,则需要检查。

  • 在使用之前,必须检查$p->prevPage、$p->nextPage、$p->pageOfPrevSet和$p->pageOfNextSet属性是否为null。