Define a model class hierarchy in CakePHP

By default, CakePHP has an AppModel class, and each application model inherits it. A common design pattern for exchanging logic between models is to create behavior and configure the model to $actAs such behavior.

But what if I wanted to introduce a hierarchy of model classes like this ?:

 AppModel |__ Vehicle |__ Car |__ Bike |__ Helicopter 

I tried to create a Vehicle class that inherits from AppModel , and then each child class inherits from Vehicle . But CakePHP tells me that it cannot find the Vehicle class.

How can I do this and where in the CakePHP directory tree should I create Vehicle ?

Thanks!

+4
source share
1 answer

this should not be a problem. you only need to make sure that you app :: import () is the "parent model" before declaring it. or what did you do to prevent the model from being found?

If I want to, I use lib for my "vehicle", it should not be a model in the model directory

eg. App :: import ("Lib", "Vehicle");

Car extends AppModel

Car expands car

+6
source

All Articles