segaco
segaco

Reputation: 1236

How to share model classes between applications in CakePHP?

I have two applications in CakePHP, App A an App B. I want that App B have access to the models in App A. I found that this is possible with the $modelPaths variable in the bootstrap.php file, but I have some models with the same name in both applications. Is this a problem? If this is a problem, how can I select only some models from the App A to be used by App B? If this is not a problem, how can I know what model is from App A and what is from App B? Thanks

Upvotes: 0

Views: 710

Answers (2)

Nedvajz
Nedvajz

Reputation: 1029

Bit outdated. But on Linux machines you can use symlink (https://en.wikipedia.org/wiki/Symbolic_link) to specify just models you need to share between these 2 applications.

Possible issues:
1) Not solution for same model names
2) Different datasources - in case you want to use also tables of App A from App B
3) Creating symlink for all related Behaviors, Classes

Upvotes: 0

deizel.
deizel.

Reputation: 11212

I believe that CakePHP will load the first model it finds.

If I am correct, it will start with models in your app/models/ folder (and any subdirectories it contains), then iterate through each additional class path you defined (ie. those in $modelPaths), then finally look for models in the core (ie. cake/lib/model/).

So basically, Cake will load the model in the core, unless a model exists elsewhere. It will then load the model elsewhere, unless there is an app-specific model in your applications directory.

With some basic testing you should be able to confirm if this is the case.

Upvotes: 3

Related Questions