CakePHPを使ったアプリ構築手順

このエントリーをはてなブックマークに追加
はてなブックマーク - CakePHPを使ったアプリ構築手順
Share on Facebook

いろいろPHPフレームワークを触っていると、どういう手順でアプリを構築するか忘れてしまいます。メモしておきます。

1. アプリのスケルトンをbakeする

cd /path/to/cakephp_dir
cake/console/cake bake

.
Welcome to CakePHP v1.3.2 Console
---------------------------------------------------------------
App : ecstats
Path: /path/to/cakephp_dir
---------------------------------------------------------------
What is the full path for this app including the app directory name?
 Example:/path/to/cakephp_dir/myapp
[/path/to/cakephp_dir] > y
...

2. 必要なDBを作成しておく

  • テーブル名は複数形
  • どんなテーブルにも必要なカラム
    • id
    • created
    • modified

3. 設定を行う

  • database.php
  • .htaccess
    • app/.htaccess
    • app/webroot/.htaccess

4. モデル・ビュー・コントローラーをbakeする

Bakeする順番は Model→Controller→View。(Controllerより先にViewを作ろうとしても「そんな名前のControllerは無い」と言われてエラーになる)

cd /path/to/cakedir
cake/console/cake bake -app myapp


Welcome to CakePHP v1.3.2 Console
---------------------------------------------------------------
App : myapp
Path: /path/to/cakephp_dir/myapp
---------------------------------------------------------------
Interactive Bake Shell
---------------------------------------------------------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)

# M->C->Vの順にbakeしていく
# ...

5. アクセスしてみて、うまく表示されれば成功

設定が正しければ、下のような文字がブラウザに表示されます。

Sweet, "SalesReport" got Baked by CakePHP!

Your tmp directory is writable.

The FileEngine is being used for caching. To change the config edit APP/config/core.php

Your database configuration file is present.

Cake is able to connect to the database.

参考

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>