Paginator Adapters
Paginator behavior depends on which adapter you create.
Array adapter
ArrayPaginator is the simple option for already-loaded data.
Use it when you have an in-memory array and want to slice it into pages without touching the database layer.
$paginator = PaginatorFactory::create(PaginatorType::ARRAY, [
'items' => $items,
'perPage' => 20,
'page' => 3,
]);
Input contract
itemsmust be an arrayperPageis an integerpageis an integer and defaults to1
Returned data
data()returns the current page slice as an arrayfirstItem()andlastItem()return the first and last item from that slice- when the current page has no items,
firstItem()andlastItem()returnnull
Good fit
Choose this adapter when the source data is already in memory, such as filtered config rows, API results you already fetched, or custom service output.
Model adapter
ModelPaginator paginates a Quantum DbModel query.
Use it when you already have a model builder with criteria, ordering, or joins applied and you want a paginated result plus navigation metadata.
$paginator = PaginatorFactory::create(PaginatorType::MODEL, [
'model' => $postModel,
'perPage' => 15,
'page' => 2,
]);
Input contract
modelmust be aDbModelinstanceperPageis an integerpageis an integer and defaults to1
Returned data
data()returns aModelCollectionfirstItem()andlastItem()return models from that collection ornullwhen the page is empty
Query behavior that affects usage
- Build your filters and sorting first, then create the paginator.
data(),firstItem(), andlastItem()may each trigger data loading, so fetch once and reuse when possible.- If you paginate a named model class, returned rows are hydrated back into that model type.
Shared adapter behavior
Both adapters share the same paging metadata API through PaginatorInterface, including:
- current, previous, next, and last page numbers
- current, previous, next, first, and last page links
links()for the full page listgetPagination()for ready-made HTML output