牌語備忘録 -pygo

あくまでもメモです。なるべくオフィシャルの情報を参照してください。

牌語備忘録 -pygo

CakePHP を Composer 使ってプロジェクト作成する場合のメモ

(MacOSX10.8, cakephp2.4, MAMP2.1.8)

install php

$ sudo port install php55
$ sudo port install php55-openssl

ディレクトリ作成

$ mkdir project_name
$ cd project_name

.gitignore

tmp/*
[Cc]onfig/core.php
[Cc]onfig/database.php
app/tmp/*
app/[Cc]onfig/core.php
app/[Cc]onfig/database.php
!empty
Vendor/*

インストール

$ curl -sS https://getcomposer.org/installer | php -d detect_unicode=Off
composer.json
{
    "name": "example-app",
    "repositories": [
        {
            "type": "pear",
            "url": "http://pear.cakephp.org"
        }
    ],
    "require": {
        "pear-cakephp/cakephp": ">=2.4.3"
    },
    "config": {
        "vendor-dir": "Vendor/"
    }
}
$ php composer.phar install

cake bake project

$ Vendor/bin/cake bake project app

プラグイン追加

composer.json
{
    "name": "example-app",
    "repositories": [
        {
            "type": "pear",
            "url": "http://pear.cakephp.org"
        }
    ],
    "require": {
        "pear-cakephp/cakephp": ">=2.4.3"
    },
    "require-dev": {
        "cakephp/debug_kit": "2.2.*",
        "phpunit/phpunit": "3.7.*"     },
    "extra": {
        "installer-paths":
        {
            "app/Plugin/DebugKit": ["cakephp/debug_kit"]
        }
    }, 
    "config": {
        "vendor-dir": "Vendor/"
    }
}
$ php composer.phar update

絶対パスから相対パスに変更

app/webroot/index.php
-define('CAKE_CORE_INCLUDE_PATH',  DS . 'Users' . DS . 'username' . DS . 'app_dir' . DS . 'Vendor' . DS . 'pear-pear.cakephp.org' . DS . 'CakePHP');
+define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'Vendor/pear-pear.cakephp.org/CakePHP');
app/webroot/test.php
-define('CAKE_CORE_INCLUDE_PATH',  DS . 'Users' . DS . 'username' . DS . 'app_dir' . DS . 'Vendor' . DS . 'pear-pear.cakephp.org' . DS . 'CakePHP');
+define('CAKE_CORE_INCLUDE_PATH', ROOT . DS . 'Vendor/pear-pear.cakephp.org/CakePHP');
app/Console/cake.php
	// the following line differs from its sibling
	// /app/Console/cake.php
-	* ini_set('include_path', $root . PATH_SEPARATOR .  $ds . 'Users' . $ds . 'username' . $ds  . 'app_dir' . $ds . 'Vendor' . $ds . 'pear-pear.cakephp.org' . $ds . 'CakePHP' . PATH_SEPARATOR . ini_get('include_path')); */
+	ini_set('include_path', $root . $ds . 'Vendor' . $ds . 'pear-pear.cakephp.org' . $ds . 'CakePHP' . PATH_SEPARATOR . ini_get('include_path'));

app/Config/database.php

<?php
class DATABASE_CONFIG {

    public $default = array(
        'datasource' => 'Database/Mysql',
        'persistent' => false,
        'host' => 'localhost',
        'unix_socket' => '/Applications/MAMP/tmp/mysql/mysql.sock',
        'login' => 'sample',
        'password' => 'sample',
        'database' => 'cake_sample',
        'encoding' => 'utf8'
    );
}

composerのautoloadとプラグインを読み込む

debug_kit を読み込む

app/Config/bootstrap.php
+
+require ROOT . '/Vendor/autoload.php';
+
+spl_autoload_unregister(array('App', 'load'));
+spl_autoload_register(array('App', 'load'), true, true);
+
+CakePlugin::loadAll();
確認


モデル・コントローラ・ビュー作成

MySQLにデータベース作成してbake all

$ app/Console/cake bake all