Logo Pagination

Pagination

Tổ chức
api-platform
pagination

Configures collection pagination in API Platform — page-based (default), items-per-page, client-controlled page size, maximum items, disabling, partial pagination, and cursor-based pagination. Use whenever the user mentions pagination, page size, itemsPerPage, paginating a collection, "too many results", slow COUNT queries on large tables, infinite scroll, cursor pagination, or returning a Paginator from a custom provider — even if they don't say "pagination" explicitly.

Tổng quan

Nhà phát hànhapi-platform
Kho mãskillset
Tên kỹ năngpagination
Sao
29
Bản fork
1
Tệp đi kèm
Chỉ có hướng dẫn
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Đầy đủ trong hướng dẫn

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được api-platform công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Pagination trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/api-platform/skillset/tree/main/skills/pagination
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/api-platform/skillset.git /tmp/skillset
mkdir -p .claude/skills
cp -r /tmp/skillset/skills/pagination .claude/skills/pagination
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Pagination trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Pagination ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Pagination không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

Pagination

Pagination is enabled by default on every collection, 30 items per page, page number in the page query parameter. The Hydra response carries a PartialCollectionView with first/last/next/previous links and totalItems. Most tuning is done with pagination* attributes on #[ApiResource] or a single operation — operation-level wins over resource-level wins over global config.

Items per page

php
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;

#[ApiResource(paginationItemsPerPage: 20)]            // resource default
#[GetCollection(paginationItemsPerPage: 100)]         // override one operation
class Book {}

Global default:

yaml
# config/packages/api_platform.yaml
api_platform:
    defaults:
        pagination_items_per_page: 30

Letting the client choose the page size

Off by default (a client could otherwise ask for a million rows). Opt in, then cap it with paginationMaximumItemsPerPage so the client can't DoS the database:

php
#[ApiResource(
    paginationClientItemsPerPage: true,
    paginationMaximumItemsPerPage: 100,
)]
class Book {}

GET /books?itemsPerPage=50 now works (clamped to 100). The parameter name is itemsPerPage by default; change it under collection.pagination.items_per_page_parameter_name.

Letting the client toggle pagination on/off

php
#[ApiResource(paginationClientEnabled: true)]
class Book {}

GET /books?pagination=false returns the full collection. The value goes through PHP's FILTER_VALIDATE_BOOLEAN, so false/0/no all disable it.

Disabling pagination

Per resource or per operation:

php
#[ApiResource(paginationEnabled: false)]
#[GetCollection(paginationEnabled: false)]
class Book {}

Globally under defaults.pagination_enabled: false. Only do this for collections you know stay small — an unbounded collection is an availability risk.

Partial pagination

Default pagination issues a COUNT query to compute totalItems and the last page. On huge tables that COUNT dominates the request. Partial pagination skips it: you lose totalItems and last, but keep a next link (computed by fetching one extra row). This is the right mode for "infinite scroll" UIs that only need "is there more?".

php
#[ApiResource(paginationPartial: true)]
#[GetCollection(paginationPartial: true)]
class Book {}

Client-controlled variant: paginationClientPartial: true enables GET /books?partial=true.

Cursor-based pagination

Page-based pagination drifts when rows are inserted/deleted between requests (an item can appear twice or be skipped). Cursor-based pagination anchors on a unique, ordered field instead. It requires partial pagination plus a RangeFilter and an OrderFilter on the cursor field:

php
use ApiPlatform\Metadata\ApiFilter;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\RangeFilter;

#[ApiResource(
    paginationPartial: true,
    paginationViaCursor: [
        ['field' => 'id', 'direction' => 'DESC'],
    ],
)]
#[ApiFilter(RangeFilter::class, properties: ['id'])]
#[ApiFilter(OrderFilter::class, properties: ['id' => 'DESC'])]
class Book {}

The response's view then contains cursor links (id[lt]=…) instead of page=N. Use the ODM filter namespace (ApiPlatform\Doctrine\Odm\Filter\…) for MongoDB.

Doctrine ORM paginator tuning

The ORM PaginationExtension inspects the QueryBuilder to decide two Doctrine Paginator settings. Override the guesses when the query is unusual:

  • paginationFetchJoinCollection — set true when the query joins a collection-valued association (Doctrine then runs an extra query to count distinct roots correctly). API Platform usually detects this; force it when a to-many join produces a wrong totalItems.
  • paginationUseOutputWalkers — output walkers are required for some queries (e.g. HAVING); they cost performance. Set false to disable when you know the query is simple, true when a complex query throws.
php
#[ApiResource(paginationFetchJoinCollection: false)]
#[GetCollection(name: 'with_join', paginationFetchJoinCollection: true)]
class Book {}

Pagination in custom state providers

The Doctrine/Eloquent providers paginate for you. A custom provider (see state-provider) must return a paginator itself, or the collection comes back unpaginated with no Hydra view. Return one of:

  • ApiPlatform\State\Pagination\ArrayPaginator — you already have all results in memory and want a page sliced out.
  • ApiPlatform\State\Pagination\TraversablePaginator — you fetched exactly the current page (e.g. an external API that paginates server-side) and know the totals.

ArrayPaginator takes the full array plus offset/limit:

php
use ApiPlatform\State\Pagination\ArrayPaginator;
use ApiPlatform\State\Pagination\Pagination;
use ApiPlatform\State\ProviderInterface;
use ApiPlatform\Metadata\Operation;

final class BookProvider implements ProviderInterface
{
    public function __construct(private Pagination $pagination) {}

    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ArrayPaginator
    {
        $results = $this->fetchEverything();
        [$page, $offset, $limit] = $this->pagination->getPagination($operation, $context);

        return new ArrayPaginator($results, $offset, $limit);
    }
}

TraversablePaginator is for when you only hold one page and know the totals — its constructor is (\Traversable $items, float $currentPage, float $itemsPerPage, float $totalItems):

php
use ApiPlatform\State\Pagination\TraversablePaginator;

return new TraversablePaginator(
    new \ArrayIterator($pageItems),
    currentPage: $page,
    itemsPerPage: $limit,
    totalItems: $remoteTotalCount,
);

Inject ApiPlatform\State\Pagination\Pagination to resolve the effective page, offset and limit from the operation + request — don't read ?page off the request yourself, or you'll bypass the resource's paginationItemsPerPage/client toggles.

Both classes also implement HasNextPagePaginatorInterface (hasNextPage()), so a partial-style next link works without a total. Implement PartialPaginatorInterface directly only if you genuinely can't compute totals.

Laravel

The pagination* attributes (paginationItemsPerPage, paginationClientItemsPerPage, paginationMaximumItemsPerPage, paginationEnabled, paginationPartial, paginationClientEnabled/…Partial) and the Hydra view are the same. Differences:

  • Global defaults live in config/api-platform.php under defaults and pagination (pagination_items_per_page, page_parameter_name, items_per_page_parameter_name, etc.) — not YAML.
  • The Eloquent CollectionProvider paginates with paginate() (full) or simplePaginate() (partial), returning ApiPlatform\Laravel\Eloquent\Paginator / PartialPaginator. Custom Eloquent providers can still return the framework-neutral ArrayPaginator / TraversablePaginator.
  • Doctrine-only, no Eloquent equivalent: paginationViaCursor (cursor pagination) and the ORM paginator tuning (paginationFetchJoinCollection, paginationUseOutputWalkers).

Checklist

  • Default pagination left on for unbounded collections
  • paginationClientItemsPerPage paired with paginationMaximumItemsPerPage
  • paginationPartial used where the COUNT query is the bottleneck
  • Cursor pagination has both RangeFilter and OrderFilter on the cursor field
  • Custom providers return ArrayPaginator/TraversablePaginator, not a bare array
  • Page/offset/limit read via injected Pagination, not the raw request

Câu hỏi thường gặp

Kỹ năng AI Pagination làm được gì?

Configures collection pagination in API Platform — page-based (default), items-per-page, client-controlled page size, maximum items, disabling, partial pagination, and cursor-based pagination. Use whenever the user mentions pagination, page size, itemsPerPage, paginating a collection, "too many results", slow COUNT queries on large tables, infinite scroll, cursor pagination, or returning a Paginator from a custom provider — even if they don't say "pagination" explicitly.

Vì sao nên dùng Pagination trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Pagination là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Pagination trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/api-platform/skillset/tree/main/skills/pagination. TypingMind đọc tệp SKILL.md và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Pagination?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Pagination với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Pagination với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Pagination có miễn phí không?

Kỹ năng này được api-platform phát hành trên GitHub. Hãy xem điều khoản giấy phép trong kho mã. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇