edo1z blog

プログラミングなどに関するブログです

cakePHPをcomposerでインストールする

参考: http://book.cakephp.org/2.0/ja/installation/advanced-installation.html https://getcomposer.org/download/

mkdir compo1
cd compo1
touch composer.json
vim composer.json
{
    "name": "compo1",
    "repositories": [
        {
            "type": "pear",
            "url": "http://pear.cakephp.org"
        }
    ],
    "require": {
        "pear-cakephp/cakephp": ">=2.3.4"
    },
    "config": {
        "vendor-dir": "Vendor/"
    }
}
curl -sS https://getcomposer.org/installer | php
php composer.phar install
Vendor/bin/cake bake project sample1

これで、/compo1/sample1にプロジェクトが作成された。

bake projectの結果 スクリーンショット 2014-05-08 11.49.01

デフォルトでは、 bake は CAKE_CORE_INCLUDE_PATH をハードコードするようになっています。 アプリケーションの移植性を高めるためには、 webroot/index.php を修正し、 CAKE_CORE_INCLUDE_PATH を相対パスに変更しましょう:

って書いてあるし何かする必要があるらしい。 CAKE_CORE_INCLUDE_PATHは、ルートの lib ディレクトリへのパスです。

webroot/index.phpには、CAKE_CORE_INCLUDE_PATHは下記のように設定されている。

define('CAKE_CORE_INCLUDE_PATH',  DS . 'vagrant' . DS . 'html' . DS . 'compo1' . DS . 'Vendor' . DS . 'pear-pear.cakephp.org' . DS . 'CakePHP');

これを相対化すればいいらしい。ああそうかそうしないとgithubとかで共有できないのじゃな。いやー勉強なった。 きっとcakePHP3だと相対化してくれるんだろう。

define(
    'CAKE_CORE_INCLUDE_PATH',
    ROOT . '/Vendor/pear-pear.cakephp.org/CakePHP'
);