cakephp1.2 or 1.3でmodel/componentなどを共有する方法
cakephpで複数のプロジェクトを作成したとき、お互いにmodelやcomponentを共有したいときは稀にありますよね。たとえば、nanapiの場合ですとPC版モバイル版もあったりします。
そんな時、プロジェクトは別にするけど一部共有したいmodelがでてきます。最初はmodelをコピーしてつかっていたのですが、複数管理が非常に面倒だったため共有する方法を調べてみました。
cakephp1.2の場合
共有の方法は、1.2と1.3で変更されています。まずは1.2の方法を紹介します。
- app/config/bootstrap.php
<?php $modelPaths = array( '/path/to/project_1/app/models/', '/path/to/project_2/app/models/', ); $componentPaths = array( '/path/to/project_1/app/controllers/components/', '/path/to/project_2/app/controllers/components/', );
cakephp1.3の場合
- app/config/bootstrap.php
<?php App::build(array( 'models' => array( '/path/to/project_1/app/models/', '/path/to/project_2/app/models/', ), 'components' => array( '/path/to/project_1/app/controllers/components/', '/path/to/project_2/app/controllers/components/', ), ) );
こんな感じで他のパスを追加することができます。
こうすることで、複数のファイルを管理する手間が省けますね。