CakePHP从远程目录扩展模型

I'm trying to do something unorthodox. I have 2 cakePHP installations within one directory. Is it possible to extend a model from one of my app installations into another?

This is what my directory structure looks like:

app1
  app
    model
      * app1Model
    view
    controller
  libs
  plugins
  ventors

app2
  app
    model
      * app2Model (I want to extent this model with app1Model)
    view
    controller
  libs
  plugins
  ventors

I want my app2Model to extend app1Model.

You sure can! What you're looking for is App::build(). It allows you to let Cake search other directories when you use App::uses(). For example, you could add the additional path to models like so:

// assuming your app is under `/var/www`
App::build(array(
  'Model' => array(
    '/var/www/app1/app/model'
  )
));

You use App::build() to tell Cake "when I use App::uses(), look for classes here as well". You would place the code above in your bootstrap file in app2 to tell cake "also look for models in /var/www/app1/app/model.

Now in app2, when you use:

App::uses('app1Model', 'Model');

It will look both in app2/app/model and /var/www/app1/app/model for models named app1Model. You can use App::build() to point to other things like controllers and plugins as well, as indicated in the doc.

Beware of conflicting names. From the looks of it, you might want to consider building a plugin instead.