AppModel equivalent in CakePHP4

CakePHP 2 used to have the “AppModel” which would extend Model and allowed for application wide methods. I note that CakePHP 4 doesn’t seem to have this. How would this be handled today?

1 Like

There’s nothing magical about the AppModel structure, it’s just plain old PHP class structure. So, make your own AppModel class with whatever you need in it, and extend your models from that.

Thanks, although my question mightn’t have been clear. Given “AppModel” was available as standard in 2 but not in 3 / 4, I was wondering if there was a reason for removing it, a preferred way of handling this scenarios etc.

Will add AppModel in this app.

I can’t find any obvious documentation about why it was eliminated. My guess is that something in the structure of v1/2 required it, but that became optional in v3. Perhaps to do with namespaces, or the new ORM.

2 Likes