# Paginator Error When Setting a View Variable in AppController

**URL:** <https://discourse.cakephp.org/t/paginator-error-when-setting-a-view-variable-in-appcontroller/12950>\
**Category:** Uncategorized\
**Created:** [June 16, 2026, 9:25am UTC](https://discourse.cakephp.org/t/paginator-error-when-setting-a-view-variable-in-appcontroller/12950 "2026-06-16T09:25:45Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Johnadam](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/johnadam/32/3384_2.png) [@Johnadam](https://discourse.cakephp.org/u/Johnadam)\
**Post date:** [June 16, 2026, 9:25am UTC](https://discourse.cakephp.org/t/paginator-error-when-setting-a-view-variable-in-appcontroller/12950/1 "2026-06-16T09:25:45Z")

</div>

Hi everyone,

I’m encountering an odd issue after upgrading to CakePHP 5.1.12.

In several controllers, I usually set a view variable like this:

```auto
$this->set('menuID', $this->product->navigation_id);

```

The value is definitely an integer, and this approach worked fine in previous 4.x versions.

However, if I move the following line to `AppController`:

```auto
$this->set('menuID', 3);

```

all `index` pages start throwing this error:

```auto
Cake\View\View::get(): Argument #1 ($var) must be of type string, int given,
called in ...\src\View\Helper\PaginatorHelper.php

```

I can avoid the issue by not setting `menuID` in `AppController`, so it’s not blocking my work. I’m mainly curious whether this is an intended change in CakePHP 5.x or if I’m overlooking something.

Has anyone experienced the same behavior or knows what could be causing it?

Thanks in advance!

Kind regards,  
Klaus

---

<div class="post-metadata">

**Author:** ![dereuromark](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/dereuromark/32/37_2.png) [@dereuromark](https://discourse.cakephp.org/u/dereuromark)\
**Post date:** [June 16, 2026, 1:22pm UTC](https://discourse.cakephp.org/t/paginator-error-when-setting-a-view-variable-in-appcontroller/12950/2 "2026-06-16T13:22:21Z")

</div>

Another workaround for now is probably:

```auto
$this->set('menuID', (string)3);

```

But best to actually debug what viewVars in the View itself contains after your set() call.  
This might help to narrow it down.

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [June 17, 2026, 2:09pm UTC](https://discourse.cakephp.org/t/paginator-error-when-setting-a-view-variable-in-appcontroller/12950/3 "2026-06-17T14:09:00Z")

</div>

Frist of all - CakePHP [5.1.12](https://github.com/cakephp/cakephp/releases/tag/5.1.12) is not a thing, do you mean [5.2.12](https://github.com/cakephp/cakephp/releases/tag/5.2.12)?

Then it would help you post the whole stacktrace as we have no idea where in which part of the rendering process you are.

* * *

From what I can say - if we are on 5.2.12 - the only `Cake\View\View::get()` method call inside the PaginatorHelper class comes from here [cakephp/src/View/Helper/PaginatorHelper.php at 5.2.12 · cakephp/cakephp · GitHub](https://github.com/cakephp/cakephp/blob/5.2.12/src/View/Helper/PaginatorHelper.php#L142)

This indicates, that you have a view variable in there, which is actually an integer - as if you did something like

```php
$this->set([123 => 'something']);

```

Because literrally this call gives me the exact issue you have right now.

* * *

You can debug the existing view variables before the rendering happens via

```php
dd($this->viewBuilder()->getVars());

```

and make sure your debug mode is enabled.

Then it should be pretty obvious which variable is wrong

 ![image](https://canada1.discourse-cdn.com/flex029/uploads/cakephp/original/2X/8/863d9f5ecce6619754457f602d7f78cf83ddf202.jpeg)

---

<div class="post-metadata">

**Author:** ![Harper.Scott62](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@Harper.Scott62](https://discourse.cakephp.org/u/Harper.Scott62)\
**Post date:** [August 15, 2026, 8:39am UTC](https://discourse.cakephp.org/t/paginator-error-when-setting-a-view-variable-in-appcontroller/12950/4 "2026-08-15T08:39:44Z")

</div>

I’m seeing the same type mismatch after moving the view variable assignment in CakePHP 5.1.12, even though the value is an integer by design. The PaginatorHelper path in the error makes this look like a regression in how paginator variables are read.

---

<div class="post-metadata">

**Author:** ![KevinPfeifer](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/kevinpfeifer/32/3365_2.png) [@KevinPfeifer](https://discourse.cakephp.org/u/KevinPfeifer)\
**Post date:** [August 15, 2026, 7:10pm UTC](https://discourse.cakephp.org/t/paginator-error-when-setting-a-view-variable-in-appcontroller/12950/5 "2026-08-15T19:10:58Z")

</div>

Again, 5.1.12 is not a thing. Are you on 5.2.12?

---

<div class="post-metadata">

**Author:** ![Harper.Scott62](https://avatars.discourse-cdn.com/v4/letter/h/ecae2f/32.png) [@Harper.Scott62](https://discourse.cakephp.org/u/Harper.Scott62)\
**Post date:** [August 16, 2026, 2:19pm UTC](https://discourse.cakephp.org/t/paginator-error-when-setting-a-view-variable-in-appcontroller/12950/6 "2026-08-16T14:19:02Z")

</div>

I’m seeing the same paginator type mismatch after moving the view variable assignment in CakePHP, and the exact installed package version seems important here. I’m checking the reported version against the actual composer.lock entry before treating this as a PaginatorHelper regression.
