getFlash() from Cake/Http/ServerRequest

I’m following the tutorial of the Authorization plugin and Im facing issues at

$request->getFlash()->error( ‘You are not authorized to access that location’ );

I get the following message:

Method “getFlash()” does not exist, BadMethodCallException

Using get_class() I know $request is an instance of Cake/Http/ServerRequest and according to the API the method should exist.

Also, looking into vendor/cakephp/cakephp/src/Http/ServerRequest.php I cant find that method.

PD: using CakePHP v4.1.7

You are looking at the API Doc for CakePHP 4.2
Since you are on 4.1.7 you don’t have that method yet because it was added in 4.2
See 4.2 Migration Guide - 4.x

Thanks for the fast response! I will migrate to the last version.