# Pagination - upgrade from CakePHP 4.3 to 4.4

**URL:** <https://discourse.cakephp.org/t/pagination-upgrade-from-cakephp-4-3-to-4-4/11971>\
**Category:** Need Help\
**Created:** [April 4, 2024, 4:22pm UTC](https://discourse.cakephp.org/t/pagination-upgrade-from-cakephp-4-3-to-4-4/11971 "2024-04-04T16:22:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrebeschi](https://avatars.discourse-cdn.com/v4/letter/m/67e7ee/32.png) [@mrebeschi](https://discourse.cakephp.org/u/mrebeschi)\
**Post date:** [April 4, 2024, 4:22pm UTC](https://discourse.cakephp.org/t/pagination-upgrade-from-cakephp-4-3-to-4-4/11971/1 "2024-04-04T16:22:06Z")

</div>

I am upgrading to CakePHP 4.4, and the Paginator component I was using previously has been deprecated.

I am using the pagination on a controller that’s meant for an API endpoint, which means, I have no templates because I’m using a JSON view:

```auto
    public function initialize(): void
    {
        parent::initialize();

        $this->viewBuilder()
            ->setClassName('Json');
    }

```

In CakePHP 4.3, I used to be able to call `$this->Paginator->getPagingParams()` to access the page count, which I was then outputting together with my results, IE:

```auto
    public function list(int $limit = 10, int $page = 1)
    {
        $query = $this->People->find('visible')
            ->order(['lastname' => 'ASC']);

        $paginateSettings = [
            'limit' => $limit,
            'page' => $page,
            'maxLimit' => 100
        ];

        $this->set('people', $this->paginate($query, $paginateSettings));

        $this->set('page', $page);
        $pagingParams = $this->Paginator->getPagingParams();
        $this->set('pages', $pagingParams['People']['pageCount']);

        $this->viewBuilder()
            ->setOption('serialize', ['people', 'page', 'pages']);
    }

```

This was working perfectly, allowing me to use the `page` and `pages` on the client side to navigate the pagination.

Where can I find the total number of pages now? Am I supposed to use the `PaginatorHelper`? I see from [the documentation](https://book.cakephp.org/4/en/views/helpers/paginator.html#checking-the-pagination-state) that it has a `total` method.  
However, how can I access that in a controller? I’ve tried adding `->addHelper('Paginator')` both to my `initialize` and `beforeRender` methods in the controller but I still can’t access `$this->Paginator`.  
Is this the right way, and I’m somehow doing it wrong? Or is there another way to get the total number of pages that the paginator is creating without using `PaginatorHelper`?

---

<div class="post-metadata">

**Author:** ![deanoj](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@deanoj](https://discourse.cakephp.org/u/deanoj)\
**Post date:** [April 4, 2024, 4:35pm UTC](https://discourse.cakephp.org/t/pagination-upgrade-from-cakephp-4-3-to-4-4/11971/2 "2024-04-04T16:35:20Z")

</div>

I was literally about to ask the exact same question… so rather than post my own I’ll keep an eye out for answers. 🙂

---

<div class="post-metadata">

**Author:** ![deanoj](https://avatars.discourse-cdn.com/v4/letter/d/bcef8e/32.png) [@deanoj](https://discourse.cakephp.org/u/deanoj)\
**Post date:** [April 4, 2024, 4:42pm UTC](https://discourse.cakephp.org/t/pagination-upgrade-from-cakephp-4-3-to-4-4/11971/3 "2024-04-04T16:42:29Z")

</div>

I may have found the answer, use this:

```auto
$paginationParams = $this->request->getAttribute('paging');

```

Last paragraph in this section of the cookbook: [Pagination - 4.x](https://book.cakephp.org/4/en/controllers/pagination.html#advanced-usage)
