Call Controller method in Cakephp 5 [Solved]

Good morning,

I am in the process of upgrading one of my applications from cakephp 4 to cakephp 5.

I’m used to using a Controller named Functions handling different functions that can be used anywhere.

Until now I called the methods like this: (new MyFunctionsController())->function();

However, it seems that with cakephp 5 this is no longer possible. Is this really the case?

Do we have to use services and dependency injections?
In the FR doc, it is marked that it is experimental…

Sincerely,
Alexis

Dependency injection works just fine even in Cake 4. If you don’t like it, you can always just use a “traditional” service class; just put your “Functions” class somewhere else, not as a controller, and instantiate and call it like you have been e.g. (new \Service\MyFunctions())->function();

1 Like

Thank you Zuluru for these details. I’m going to look into dependency injections.