Zielony_Buszmen Zielony_Buszmen - 1 year ago 131
PHP Question

Extending ORM classes in CakePHP 3

I would like to extend Query class in order to create function customContain() available in every Table model. How should I do it?

Answer Source

I want to use that BleMethod() in all table models in cakephp. Where I have to add code of that function? Where I have to implements BleMethod?

Unlike Cake2 Cake3 does not feature an application level class like AppModel from where all other classes inherit from. So you have two options:

The behavior can be loaded globally to all models by using the Model.initialize event. And then loading the behavior inside the events callback. Read these pages:

But that's not what you want

customContain() indicates for me that you want to setup some contains very often. Well, use finders.

Finders can be combined:


Each custom find will add something to the query object. You can add your custom contains this way.

Read Custom Finder Methods.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download