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:
$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:
$this->set('menuID', 3);
all index pages start throwing this error:
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
Another workaround for now is probably:
$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.
Frist of all - CakePHP 5.1.12 is not a thing, do you mean 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
This indicates, that you have a view variable in there, which is actually an integer - as if you did something like
$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
dd($this->viewBuilder()->getVars());
and make sure your debug mode is enabled.
Then it should be pretty obvious which variable is wrong