Simple, Slowly

ブログを引っ越ししました。http://48.jp

CakePHP2.0を使ってみよう 準備編

CakePHP2.0のチュートリアルです。
Blog Tutorialを参考に進んでいきます。
感じを掴むのが目的なので、細かい部分は割合してます。
環境はLAMPです。


ダウンロード
GitHubレポジトリ git clone git://github.com/cakephp/cakephp.gitからソースコードを取得してください。


Creating the Blog Database
データベースを作成します。

CREATE DATABASE  `cake_blog_tutorial` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

テーブル作成を作成します。

/* First, create our posts table: */
CREATE TABLE posts (
    id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    title VARCHAR(50),
    body TEXT,
    created DATETIME DEFAULT NULL,
    modified DATETIME DEFAULT NULL
);

/* Then insert some posts for testing: */
INSERT INTO posts (title,body,created)
    VALUES ('The title', 'This is the post body.', NOW());
INSERT INTO posts (title,body,created)
    VALUES ('A title once again', 'And the post body follows.', NOW());
INSERT INTO posts (title,body,created)
    VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());


Cake Database Configuration
/app/Config/database.php.defaultをコピーしてdatabase.phpを作成します。
database.phpを適宜編集します。

<?php
public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'port' => '',
    'login' => 'cakeBlog',
    'password' => 'c4k3-rUl3Z',
    'database' => 'cake_blog_tutorial',
    'schema' => '',
    'prefix' => '',
    'encoding' => ''
);


Optional Configuration

app/Config/core.phpを編集します。
デフォルトだと警告が出るので、適当に変更してください。

187行目    Configure::write('Security.salt', 'DYhG93b0qyJfIxfs2guVniR2G0FgaC9msgjsaldkjgasli'); 
192行目    Configure::write('Security.cipherSeed', '768593096574535464510989584');

app/tmp/のパーミッションを777にします。

chmod -R 777 app/tmp/


とりあえず、これで準備はできました。
ブラウザでアクセスしてみましょう。
このように緑のバーが表示されていれば成功です。

f:id:sho-yamasaki:20120221013558p:image:w360

次回はModelとControlle、viewを作成していきます。