dmind/bucket-pagination

TYPO3 的桶分页

安装: 0

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 3

分支: 0

开放问题: 0

类型:typo3-cms-extension

v1.0.4 2022-07-15 08:06 UTC

This package is auto-updated.

Last update: 2024-09-15 16:08:28 UTC


README

GitHub

使用桶模式进行分页的分页器,允许对 POST 表单结果进行分页

安装

建议使用 composer 安装扩展,命令为 composer require dmind/bucket-pagination

推荐

对于更简单的桶分页器分页,建议使用 NumberedPaginator

用法

以下是每个分页器与 NumberedPaginator 结合使用的两个示例。

BucketPaginator

您可以传递要保存到桶中的项,可以使用生成的桶 ID 再次检索这些项。也可以更新桶中的项,因此,如果您向请求传递桶,则可以不传递项;如果需要更新桶(例如,结果发生更改),则可以传递项。

示例用法

$itemsToBePaginated = ['apple', 'banana', 'strawberry', 'raspberry', 'pineapple'];
$filter = (new Filter())->setTitle('apple');
$itemsPerPage = 10;
$maximumLinks = 15;

$currentPage = $this->request->hasArgument('currentPage') ? (int)$this->request->getArgument('currentPage') : 1;
$currentBucketId = $this->request->hasArgument('bucketId') ? $this->request->getArgument('bucketId') : '';

$paginator = new BucketPaginator(
    // if you pass new/changed items while also passing a bucket ID
    // it'll update the items in the bucket
    $currentBucketId ? null : $itemsToBePaginated,
    // optional elements to store into the bucket (f.e. filter objects)
    // the currently passed elements will be ignored if no items are passed
    // and the optional arguments from the existing bucket will be used
    ['filter' => $filter],
    // either the current bucket ID or an empty string
    // it'll generate its own bucket ID if not set based on the items and optional elements
    $currentBucketId,
    // current page to display
    $currentPage,
    // amount of items per page
    $itemsPerPage
);

$pagination = new NumberedPagination($paginator, $maximumLinks);

您也可以在模板中自由检索桶内容以及附加项

<f:if condition="{pagination.paginator.additionalContent.filter}">
    You filtered for {pagination.paginator.additionalContent.filter.title}
    <br/>
    (Bucket ID: {pagination.paginator.bucketId})
    <br/>
</f:if>
<hr/>

<f:for each="{pagination.paginator.paginatedItems}" as="item">
    {item.title}
    <br/>
</f:for>

DataSourcePaginator

另一种选择(例如,由于存储原因或刷新结果)是使用 DataSourcePaginator 从桶内容生成我们正在分页的项。优点是桶大小更小,结果自动更新。

$productRepository = GeneralUtility::makeInstance(ProductRepository::class);
$filter = (new Filter())->setTitle('apple');
$itemsPerPage = 10;
$maximumLinks = 15;

$currentPage = $this->request->hasArgument('currentPage') ? (int)$this->request->getArgument('currentPage') : 1;
$currentBucketId = $this->request->hasArgument('bucketId') ? $this->request->getArgument('bucketId') : '';

$paginator = new DataSourcePaginator(
    // the data source which implements the \Dmind\BucketPagination\DataSourceInterface
    // to retrieve the items from based on the bucket contents
    $productRepository,
    // bucket content which will be passed to the DataSource
    // if you pass new/changed arguments while also passing a bucket ID
    // it'll update the items in the bucket
    $currentBucketId ? []: ['filter' => $filter],
    // either the current bucket ID or an empty string
    // it'll generate its own bucket ID if not set based on the items and optional elements
    $currentBucketId,
    // current page to display
    $currentPage,
    // amount of items per page
    $itemsPerPage
);

$pagination = new NumberedPagination($paginator, $maximumLinks);

这里您也可以检索桶内容

<f:if condition="{pagination.paginator.bucketContent.filter}">
    You filtered for {pagination.paginator.bucketContent.filter.title}
    <br/>
    (Bucket ID: {pagination.paginator.bucketId})
    <br/>
</f:if>
<hr/>

<f:for each="{pagination.paginator.paginatedItems}" as="item">
    {item.title}
    <br/>
</f:for>

许可证

本项目采用 GPL v3.0 许可 - 请参阅 LICENSE 文件以获取详细信息