Magento 2 Experten — Hyvä Theme, Tailwind CSS & SEO aus einer Hand ›

Pagination Basics

Pagination Basics

~14 Min. Lesezeit Zuletzt aktualisiert am August 8, 2026

Chapter 28 announced it: GET /api/projects CURRENTLY returns ALL projects in ONE response – API Platform paginates AUTOMATICALLY, this just wasn't visible before due to the FEW test records.

Generating more test data

api/src/DataFixtures/AppFixtures.php
public function load(ObjectManager $manager): void
{
    for ($i = 1; $i <= 45; $i++) {
        $project = new Project();
        $project->setName(sprintf('Project %02d', $i));
        $project->setDescription(sprintf('Automatically generated test project number %d.', $i));
        $project->setPriority(random_int(1, 5));
        $manager->persist($project);
    }

    // ... tags unchanged

    $manager->flush();
}
docker compose exec php bin/console doctrine:fixtures:load --no-interaction

Testing the default pagination

curl -k https://localhost/api/projects
{
  "@context": "/api/contexts/Project",
  "@id": "/api/projects",
  "@type": "hydra:Collection",
  "hydra:member": [ /* 30 entries */ ],
  "hydra:totalItems": 45,
  "hydra:view": {
    "@id": "/api/projects?page=1",
    "@type": "hydra:PartialCollectionView",
    "hydra:first": "/api/projects?page=1",
    "hydra:last": "/api/projects?page=2",
    "hydra:next": "/api/projects?page=2"
  }
}

ONLY 30 of 45 projects in hydra:member – the DEFAULT itemsPerPage value is 30. hydra:totalItems shows the TOTAL count, hydra:view provides READY-MADE links to the next/first/last page.

Fetching the next page

curl -k 'https://localhost/api/projects?page=2'

The page query parameter controls the page – NO custom code needed, API Platform handles the LIMIT/OFFSET in the generated database query ENTIRELY on its own.

Achtung: hydra:last is MISSING from the response when paginationPartial is enabled (relevant for VERY large tables where COUNT(*) itself gets too expensive) – for OUR project the DEFAULT full count stays active.

Tipp: hydra:view is EXACTLY the field a React pagination component (block 10) should read, instead of computing hydra:totalItems and itemsPerPage ITSELF – the ready-made links avoid off-by-one errors.