Cakephp3 - Cant find $theme property that throws an error

Hello,

I have upgraded from Cakephp3 v3 to v3.3 (using Composer) and I get the following error:

Deprecated (16384): Property $theme is deprecated.
Use $this->viewBuilder()->theme() instead in beforeRender().
[CORE/src/View/ViewVarsTrait.php, line 103]

But I can’t find in my files where $theme is used. I have searched all my files for the keyword $theme and beforeRender, no relevant results.

This error is shown in all my pages, so it must be some file that is included in each one.

I have already searched on google for this issue, no relevant results either.

Has anyone else had this problem? Thanks.

Turns out that in AppController a custom theme (Orange in my case) needs to be declared as:

public function beforeRender(Event $event)
{
    $this->viewBuilder()->theme('Orange');
}

and not like

public $theme = 'Orange';

This solved my problem.

For future reference, the error messages that CakePHP makes should contain a ‘context’ link that lets you expand the stack trace of the error. That might have helped you in tracking down where the error was.

1 Like