#freeze
閲覧総計:&counter();  (本日:&counter(today);  昨日:&counter(yesterday);)

CakePHPには「Bake」という質問に答えていくだけでCakePHPのコードを自動生成してく
れる便利なツールがある。
早速、先に勉強した「ブログチュートリアル」と同じものをBakeで自動作成したみた。 08/12/31
(参考)
[[ブログチュートリアルをやってみた]]
|&attachref(blog_index画面_0.JPG,zoom,150x150,button){新しい画像添付};|&attachref(blog_view画面.JPG,zoom,150x150,button){新しい画像添付};|&attachref(blog_edit画面.JPG,zoom,150x150,button){新しい画像添付};|

【前提】
●Windowsローカル環境で/cakephp/blog2/フォルダにBakeした事例です。
●データベース名はblog、テーブル名はpostを利用した。
●日本語文字コードはEUCです。
●入力は赤文字で示した。「↓」はEnterキー。

【目次】(項目をクリックすると、そこに飛べます)
#contents
~
*プロジェクトの作成&データベース設定 [#o947097d]

コマンド プロンプトを起動
&attachref(コマンドプロンプト.JPG,zoom,250x250,button){新しい画像添付};

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\hoge>&color(red){cd C:\xampp\htdocs\cake\cake\console↓};

C:\xampp\htdocs\cake\cake\console>&color(red){php cake.php bake -app C:\xampp\htdocs\cakephp↓};

Welcome to CakePHP v1.2.0.7962 Console
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
App : cakephp
Path: C:\xampp\htdocs\cakephp
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
What is the full path for this app including the app directory name?
Example: C:\xampp\htdocs\cakephp\myapp
[C:\xampp\htdocs\cakephp\myapp] > &color(red){C:\xampp\htdocs\cakephp\blog2↓};
Bake Project
Skel Directory: C:\xampp\htdocs\cake\cake\console\libs\templates\skel
Will be copied to: C:\xampp\htdocs\cakephp\blog2
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Look okay? (y/n/q)
[y] >&color(red){↓};
Do you want verbose output? (y/n)
[n] > &color(red){y↓};
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Created: blog2 in C:\xampp\htdocs\cakephp\blog2
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
C:\xampp\htdocs\cakephp\blog2 created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\.htaccess copied to C:\xam
pp\htdocs\cakephp\blog2\.htaccess
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\app_controller.php copied
to C:\xampp\htdocs\cakephp\blog2\app_controller.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\app_helper.php copied to C
:\xampp\htdocs\cakephp\blog2\app_helper.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\app_model.php copied to C:
\xampp\htdocs\cakephp\blog2\app_model.php
C:\xampp\htdocs\cakephp\blog2\config created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\acl.ini.php copied
to C:\xampp\htdocs\cakephp\blog2\config\acl.ini.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\bootstrap.php copie
d to C:\xampp\htdocs\cakephp\blog2\config\bootstrap.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\core.php copied to
C:\xampp\htdocs\cakephp\blog2\config\core.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\database.php.defaul
t copied to C:\xampp\htdocs\cakephp\blog2\config\database.php.default
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\inflections.php cop
ied to C:\xampp\htdocs\cakephp\blog2\config\inflections.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\routes.php copied t
o C:\xampp\htdocs\cakephp\blog2\config\routes.php
C:\xampp\htdocs\cakephp\blog2\config\sql created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\sql\db_acl.php copi
ed to C:\xampp\htdocs\cakephp\blog2\config\sql\db_acl.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\sql\db_acl.sql copi
ed to C:\xampp\htdocs\cakephp\blog2\config\sql\db_acl.sql
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\sql\i18n.php copied
to C:\xampp\htdocs\cakephp\blog2\config\sql\i18n.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\sql\i18n.sql copied
to C:\xampp\htdocs\cakephp\blog2\config\sql\i18n.sql
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\sql\sessions.php co
pied to C:\xampp\htdocs\cakephp\blog2\config\sql\sessions.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\config\sql\sessions.sql co
pied to C:\xampp\htdocs\cakephp\blog2\config\sql\sessions.sql
C:\xampp\htdocs\cakephp\blog2\controllers created
C:\xampp\htdocs\cakephp\blog2\controllers\components created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\controllers\pages_controll
er.php copied to C:\xampp\htdocs\cakephp\blog2\controllers\pages_controller.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\index.php copied to C:\xam
pp\htdocs\cakephp\blog2\index.php
C:\xampp\htdocs\cakephp\blog2\locale created
C:\xampp\htdocs\cakephp\blog2\locale\eng created
C:\xampp\htdocs\cakephp\blog2\locale\eng\LC_MESSAGES created
C:\xampp\htdocs\cakephp\blog2\models created
C:\xampp\htdocs\cakephp\blog2\models\behaviors created
C:\xampp\htdocs\cakephp\blog2\models\datasources created
C:\xampp\htdocs\cakephp\blog2\plugins created
C:\xampp\htdocs\cakephp\blog2\tests created
C:\xampp\htdocs\cakephp\blog2\tests\cases created
C:\xampp\htdocs\cakephp\blog2\tests\cases\behaviors created
C:\xampp\htdocs\cakephp\blog2\tests\cases\components created
C:\xampp\htdocs\cakephp\blog2\tests\cases\controllers created
C:\xampp\htdocs\cakephp\blog2\tests\cases\helpers created
C:\xampp\htdocs\cakephp\blog2\tests\cases\models created
C:\xampp\htdocs\cakephp\blog2\tests\fixtures created
C:\xampp\htdocs\cakephp\blog2\tests\groups created
C:\xampp\htdocs\cakephp\blog2\tmp created
C:\xampp\htdocs\cakephp\blog2\tmp\cache created
C:\xampp\htdocs\cakephp\blog2\tmp\cache\models created
C:\xampp\htdocs\cakephp\blog2\tmp\cache\persistent created
C:\xampp\htdocs\cakephp\blog2\tmp\cache\views created
C:\xampp\htdocs\cakephp\blog2\tmp\logs created
C:\xampp\htdocs\cakephp\blog2\tmp\sessions created
C:\xampp\htdocs\cakephp\blog2\tmp\tests created
C:\xampp\htdocs\cakephp\blog2\vendors created
C:\xampp\htdocs\cakephp\blog2\vendors\shells created
C:\xampp\htdocs\cakephp\blog2\vendors\shells\tasks created
C:\xampp\htdocs\cakephp\blog2\vendors\shells\templates created
C:\xampp\htdocs\cakephp\blog2\views created
C:\xampp\htdocs\cakephp\blog2\views\elements created
C:\xampp\htdocs\cakephp\blog2\views\elements\email created
C:\xampp\htdocs\cakephp\blog2\views\elements\email\html created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\elements\email\html\
default.ctp copied to C:\xampp\htdocs\cakephp\blog2\views\elements\email\html\de
fault.ctp
C:\xampp\htdocs\cakephp\blog2\views\elements\email\text created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\elements\email\text\
default.ctp copied to C:\xampp\htdocs\cakephp\blog2\views\elements\email\text\de
fault.ctp
C:\xampp\htdocs\cakephp\blog2\views\errors created
C:\xampp\htdocs\cakephp\blog2\views\helpers created
C:\xampp\htdocs\cakephp\blog2\views\layouts created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\layouts\ajax.ctp cop
ied to C:\xampp\htdocs\cakephp\blog2\views\layouts\ajax.ctp
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\layouts\default.ctp
copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\default.ctp
C:\xampp\htdocs\cakephp\blog2\views\layouts\email created
C:\xampp\htdocs\cakephp\blog2\views\layouts\email\html created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\layouts\email\html\d
efault.ctp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\email\html\defa
ult.ctp
C:\xampp\htdocs\cakephp\blog2\views\layouts\email\text created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\layouts\email\text\d
efault.ctp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\email\text\defa
ult.ctp
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\layouts\flash.ctp co
pied to C:\xampp\htdocs\cakephp\blog2\views\layouts\flash.ctp
C:\xampp\htdocs\cakephp\blog2\views\layouts\js created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\layouts\js\default.c
tp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\js\default.ctp
C:\xampp\htdocs\cakephp\blog2\views\layouts\rss created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\layouts\rss\default.
ctp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\rss\default.ctp
C:\xampp\htdocs\cakephp\blog2\views\layouts\xml created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\views\layouts\xml\default.
ctp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\xml\default.ctp
C:\xampp\htdocs\cakephp\blog2\views\pages created
C:\xampp\htdocs\cakephp\blog2\views\scaffolds created
C:\xampp\htdocs\cakephp\blog2\webroot created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\webroot\.htaccess copied t
o C:\xampp\htdocs\cakephp\blog2\webroot\.htaccess
C:\xampp\htdocs\cakephp\blog2\webroot\css created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\webroot\css\cake.generic.c
ss copied to C:\xampp\htdocs\cakephp\blog2\webroot\css\cake.generic.css
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\webroot\css.php copied to
C:\xampp\htdocs\cakephp\blog2\webroot\css.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\webroot\favicon.ico copied
to C:\xampp\htdocs\cakephp\blog2\webroot\favicon.ico
C:\xampp\htdocs\cakephp\blog2\webroot\files created
C:\xampp\htdocs\cakephp\blog2\webroot\img created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\webroot\img\cake.icon.gif
copied to C:\xampp\htdocs\cakephp\blog2\webroot\img\cake.icon.gif
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\webroot\img\cake.power.gif
copied to C:\xampp\htdocs\cakephp\blog2\webroot\img\cake.power.gif
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\webroot\index.php copied t
o C:\xampp\htdocs\cakephp\blog2\webroot\index.php
C:\xampp\htdocs\cakephp\blog2\webroot\js created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\webroot\js\vendors.php cop
ied to C:\xampp\htdocs\cakephp\blog2\webroot\js\vendors.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\webroot\test.php copied to
C:\xampp\htdocs\cakephp\blog2\webroot\test.php

Creating file C:\xampp\htdocs\cakephp\blog2\views\pages\home.ctp
Wrote C:\xampp\htdocs\cakephp\blog2\views\pages\home.ctp
Welcome page created
Random hash key created for 'Security.salt'
CAKE_CORE_INCLUDE_PATH set to C:\xampp\htdocs\cake in webroot/index.php
CAKE_CORE_INCLUDE_PATH set to C:\xampp\htdocs\cake in webroot/test.php
Remember to check these value after moving to production server
Your database configuration was not found. Take a moment to create one.
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Database Configuration:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Name:
[default] >&color(red){↓};
Driver: (db2/firebird/mssql/mysql/mysqli/odbc/oracle/postgres/sqlite/sybase)
[mysql] >&color(red){↓};
Persistent Connection? (y/n)
[n] >&color(red){↓};
Database Host:
[localhost] >&color(red){↓};
Port?
[n] >&color(red){↓};
User:
[root] >&color(red){↓};
Password:
>&color(red){↓};
The password you supplied was empty. Use an empty password? (y/n)
[n] > &color(red){y↓};
Database Name:
[cake] > &color(red){blog↓};
Table Prefix?
[n] >&color(red){↓};
Table encoding?
[n] > &color(red){ujis↓};   //通常は「utf8」ですが、私の場合は公開用サーバの文字コードはEUC(ujis)なのでujisでローカル開発してます。


−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
The following database configuration will be created:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Name:         default
Driver:       mysql
Persistent:   false
Host:         localhost
User:         root
Pass:
Database:     blog
Encoding:     ujis
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Look okay? (y/n)
[y] >&color(red){↓};
Do you wish to add another database configuration?
[n] >&color(red){↓};

Creating file C:\xampp\htdocs\cakephp\blog2\config\database.php
Wrote C:\xampp\htdocs\cakephp\blog2\config\database.php

C:\xampp\htdocs\cake\cake\console>



*接続状態の確認 [#w8475443]

http://localhost/cakephp/blog2/でアクセスしてみる。
&attachref(LH_cakephp_blog2オールグリーン画面.JPG,zoom,300x300,button){新しい画像添付};
●オールグリーなら問題なし。


*modelの作成 [#u34e538c]

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\hoge>&color(red){cd C:\xampp\htdocs\cake\cake\console↓};

C:\xampp\htdocs\cake\cake\console>&color(red){php cake.php bake -app C:\xampp\htdocs\cakephp\blog2↓};


Welcome to CakePHP v1.2.0.7962 Console
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
App : blog2
Path: C:\xampp\htdocs\cakephp\blog2
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Interactive Bake Shell
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[Q]uit
What would you like to Bake? (D/M/V/C/P/Q)
> &color(red){m↓};
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Bake Model
Path: C:\xampp\htdocs\cakephp\blog2\models\
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Possible Models based on your current database:
1. Post
Enter a number from the list above, type in the name of another model, or 'q' to
exit
[q] > &color(red){1↓};
Would you like to supply validation criteria for the fields in your model? (y/n)

[y] >&color(red){↓};

Field: id
Type: integer
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Please select one of the following validation options:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
1 - alphaNumeric
2 - between
(中略)
28 - userDefined
29 - Do not do any validation on this field.
... or enter in a valid regex validation string.

[29] >&color(red){↓}; 

Field: title
Type: string
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Please select one of the following validation options:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
1 - alphaNumeric
2 - between
3 - blank
4 - boolean
5 - cc
6 - comparison
7 - custom
8 - date
9 - decimal
10 - email
11 - equalTo
12 - extension
13 - file
14 - inList
15 - ip
16 - maxLength
17 - minLength
18 - money
19 - multiple
20 - notEmpty
21 - numeric
22 - phone
23 - postal
24 - range
25 - ssn
26 - time
27 - url
28 - userDefined
29 - Do not do any validation on this field.
... or enter in a valid regex validation string.

[29] > &color(red){17↓};

Field: body
Type: text
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Please select one of the following validation options:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
1 - alphaNumeric
2 - between
(中略)
28 - userDefined
29 - Do not do any validation on this field.
... or enter in a valid regex validation string.

[29] > &color(red){17↓};

Field: created
Type: datetime
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Please select one of the following validation options:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
1 - alphaNumeric
2 - between
(中略)
28 - userDefined
29 - Do not do any validation on this field.
... or enter in a valid regex validation string.

[29] >&color(red){↓};

Field: modified
Type: datetime
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Please select one of the following validation options:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
1 - alphaNumeric
2 - between
(中略)
28 - userDefined
29 - Do not do any validation on this field.
... or enter in a valid regex validation string.

[29] >&color(red){↓};
Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)? (y/n)
[y] > &color(red){n↓};

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
The following Model will be created:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Name:       Post
Validation: Array
(
  [title] => minlength
  [body] => minlength
)

Associations:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Look okay? (y/n)
[y] >&color(red){↓};

Baking model class for Post...

Creating file C:\xampp\htdocs\cakephp\blog2\models\post.php
Wrote C:\xampp\htdocs\cakephp\blog2\models\post.php
Cake test suite not installed.  Do you want to bake unit test files anyway? (y/n)
[y] >&color(red){↓};

You can download the Cake test suite from http://cakeforge.org/projects/testsuite/

Baking test fixture for Post...

Creating file C:\xampp\htdocs\cakephp\blog2\tests\fixtures\post_fixture.php
Wrote C:\xampp\htdocs\cakephp\blog2\tests\fixtures\post_fixture.php

Baking unit test for Post...

Creating file C:\xampp\htdocs\cakephp\blog2\tests\cases\models\post.test.php
Wrote C:\xampp\htdocs\cakephp\blog2\tests\cases\models\post.test.php


*controllerの作成 [#l822b8ec]

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Interactive Bake Shell
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[Q]uit
What would you like to Bake? (D/M/V/C/P/Q)
> &color(red){c↓};
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Bake Controller
Path: C:\xampp\htdocs\cakephp\blog2\controllers\
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Possible Controllers based on your current database:
1. Posts
Enter a number from the list above, type in the name of another controller, or 'q' to exit
[q] > &color(red){1↓};
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Baking PostsController
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Would you like to build your controller interactively? (y/n)
[y] >&color(red){↓};
Would you like to use scaffolding? (y/n)
[n] >&color(red){↓};
Would you like to include some basic class methods (index(), add(), view(), edit())? (y/n)
[n] > &color(red){y↓};
Would you like to create the methods for admin routing? (y/n)
[n] >&color(red){↓};
Would you like this controller to use other helpers besides HtmlHelper and FormHelper? (y/n)
[n] >&color(red){↓};
Would you like this controller to use any components? (y/n)
[n] >&color(red){↓};
Would you like to use Sessions? (y/n)
[y] > &color(red){n↓};

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
The following controller will be created:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Controller Name:  Posts
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Look okay? (y/n)
[y] >&color(red){↓};

Creating file C:\xampp\htdocs\cakephp\blog2\controllers\posts_controller.php
Wrote C:\xampp\htdocs\cakephp\blog2\controllers\posts_controller.php
Cake test suite not installed.  Do you want to bake unit test files anyway? (y/n)
[y] >&color(red){↓};

You can download the Cake test suite from http://cakeforge.org/projects/testsuite/

Baking unit test for Posts...

Creating file C:\xampp\htdocs\cakephp\blog2\tests\cases\controllers\posts_controller.test.php
Wrote C:\xampp\htdocs\cakephp\blog2\tests\cases\controllers\posts_controller.test.php

*viewの作成 [#de595052]

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Interactive Bake Shell
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[Q]uit
What would you like to Bake? (D/M/V/C/P/Q)
> &color(red){v↓};
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Bake View
Path: C:\xampp\htdocs\cakephp\blog2\views\
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Possible Controllers based on your current database:
1. Posts
Enter a number from the list above, type in the name of another controller, or 'q' to exit
[q] > &color(red){1↓};
Would you like to create some scaffolded views (index, add, view, edit) for this controller?
NOTE: Before doing so, you'll need to create your controller and model classes (including associated models). (y/n)
[n] > &color(red){y↓};
Would you like to create the views for admin routing? (y/n)
[y] > &color(red){n↓};

Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\index.ctp
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\index.ctp

Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\view.ctp
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\view.ctp

Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\add.ctp
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\add.ctp

Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\edit.ctp
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\edit.ctp
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−

View Scaffolding Complete.

−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Interactive Bake Shell
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[Q]uit
What would you like to Bake? (D/M/V/C/P/Q)
> &color(red){q↓};

C:\xampp\htdocs\cake\cake\console>



*完成品の動作確認 [#y0de05f0]

http://www.hoge.co.jp/cakephp/blog/myapp/posts/にアクセスし、下記画面が表示されればOK。
|&attachref(Bake_blog_index画面.JPG,zoom,150x150,button){新しい画像添付};|&attachref(Bake_blog_view画面.JPG,zoom,150x150,button){新しい画像添付};|&attachref(Bake_blog_edit画面.JPG,zoom,150x150,button){新しい画像添付};|


*自動生成されたコードの確認 [#n31b4382]

**/config/database.phpの自動生成コード [#m9930e38]

/cakephp/blog2/config/database.php
 <?php
 <?php
 class DATABASE_CONFIG {
 
     var $default = array(
         'driver' => 'mysql',
         'persistent' => false,
         'host' => 'localhost',
         'login' => 'root',
         'password' => '',
         'database' => 'blog',
         'encoding' => 'ujis'
     );
 }
 ?>


**modelの自動生成コード [#o554cebf]

/cakephp/blog2/models/post.php
 <?php
 class Post extends AppModel {
 
     var $name = 'Post';
     var $validate = array(
         'title' => array('minlength'),
         'body' => array('minlength')
     );
 
 }
 ?>


**controllerの自動生成コード [#e3d2e551]

特にposts_controller.phpの自動生成コードは参考になります。
/cakephp/blog2/controllers/posts_controller.php
 <?php
 class PostsController extends AppController {
 
     var $name = 'Posts';
     var $helpers = array('Html', 'Form');
 
     function index() {
         $this->Post->recursive = 0;
         $this->set('posts', $this->paginate());
     }
 
     function view($id = null) {
         if (!$id) {
             $this->flash(__('Invalid Post', true), array('action'=>'index'));
         }
         $this->set('post', $this->Post->read(null, $id));
     }
 
     function add() {
         if (!empty($this->data)) {
             $this->Post->create();
             if ($this->Post->save($this->data)) {
                 $this->flash(__('Post saved.', true), array('action'=>'index'));
             } else {
             }
         }
     }
 
     function edit($id = null) {
         if (!$id && empty($this->data)) {
             $this->flash(__('Invalid Post', true), array('action'=>'index'));
         }
         if (!empty($this->data)) {
             if ($this->Post->save($this->data)) {
                 $this->flash(__('The Post has been saved.', true), array('action'=>'index'));
             } else {
             }
         }
         if (empty($this->data)) {
             $this->data = $this->Post->read(null, $id);
         }
     }
 
     function delete($id = null) {
         if (!$id) {
             $this->flash(__('Invalid Post', true), array('action'=>'index'));
         }
         if ($this->Post->del($id)) {
             $this->flash(__('Post deleted', true), array('action'=>'index'));
         }
     }
 
 }
 ?>



**viewの自動生成コード [#qc2f1006]
/cakephp/blog/myapp/views/posts/index.ctp
 <div class="posts index">
 <h2><?php __('Posts');?></h2>
 <p>
 <?php
 echo $paginator->counter(array(
 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on reco rd 
 %start%, ending on %end%', true)
 ));
 ?></p>
 <table cellpadding="0" cellspacing="0">
 <tr>
     <th><?php echo $paginator->sort('id');?></th>
     <th><?php echo $paginator->sort('title');?></th>
     <th><?php echo $paginator->sort('body');?></th>
     <th><?php echo $paginator->sort('created');?></th>
     <th><?php echo $paginator->sort('modified');?></th>
     <th class="actions"><?php __('Actions');?></th>
 </tr>
 <?php
 $i = 0;
 foreach ($posts as $post):
     $class = null;
     if ($i++ % 2 == 0) {
         $class = ' class="altrow"';
     }
 ?>
     <tr<?php echo $class;?>>
         <td>
             <?php echo $post['Post']['id']; ?>
         </td>
         <td>
             <?php echo $post['Post']['title']; ?>
         </td>
         <td>
             <?php echo $post['Post']['body']; ?>
         </td>
         <td>
             <?php echo $post['Post']['created']; ?>
         </td>
         <td>
             <?php echo $post['Post']['modified']; ?>
         </td>
         <td class="actions">
             <?php echo $html->link(__('View', true), array('action'=>'view', $post['Post']['id'])); ?>
             <?php echo $html->link(__('Edit', true), array('action'=>'edit', $post['Post']['id'])); ?>
             <?php echo $html->link(__('Delete', true), array('action'=>'delete', $post['Post']['id']), 
             n ull, sprintf(__('Are you sure you want to delete # %s?', true), $post['Post']['id'])); ?>
         </td>
     </tr>
 <?php endforeach; ?>
 </table>
 </div>
 <div class="paging">
     <?php echo $paginator->prev('<< '.__('previous', true), array(), null, array('class'=>'disabled'));? >
  |  <?php echo $paginator->numbers();?>
     <?php echo $paginator->next(__('next', true).' >>', array(), null, array('class'=>'disabled'));?>
 </div>
 <div class="actions">
     <ul>
         <li><?php echo $html->link(__('New Post', true), array('action'=>'add')); ?></li>
     </ul>
 </div>


/cakephp/blog/myapp/views/posts/view.ctp
 <div class="posts view">
 <h2><?php  __('Post');?></h2>
     <dl><?php $i = 0; $class = ' class="altrow"';?>
         <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Id'); ?></dt>
         <dd<?php if ($i++ % 2 == 0) echo $class;?>>
             <?php echo $post['Post']['id']; ?>
             &nbsp;
         </dd>
         <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Title'); ?></dt>
         <dd<?php if ($i++ % 2 == 0) echo $class;?>>
             <?php echo $post['Post']['title']; ?>
             &nbsp;
         </dd>
         <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Body'); ?></dt>
         <dd<?php if ($i++ % 2 == 0) echo $class;?>>
             <?php echo $post['Post']['body']; ?>
             &nbsp;
         </dd>
         <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Created'); ?></dt>
         <dd<?php if ($i++ % 2 == 0) echo $class;?>>
             <?php echo $post['Post']['created']; ?>
             &nbsp;
         </dd>
         <dt<?php if ($i % 2 == 0) echo $class;?>><?php __('Modified'); ?></dt>
         <dd<?php if ($i++ % 2 == 0) echo $class;?>>
             <?php echo $post['Post']['modified']; ?>
             &nbsp;
         </dd>
     </dl>
 </div>
 <div class="actions">
     <ul>
         <li><?php echo $html->link(__('Edit Post', true), array('action'=>'edit', $post['Post']['id']));  ?> </li>
         <li><?php echo $html->link(__('Delete Post', true), array('action'=>'delete', $post['Post']['id' ]), 
         null, sprintf(__('Are you sure you want to delete # %s?', true), $post['Post']['id'])); ?> </li>
         <li><?php echo $html->link(__('List Posts', true), array('action'=>'index')); ?> </li>
         <li><?php echo $html->link(__('New Post', true), array('action'=>'add')); ?> </li>
     </ul>
 </div>

/cakephp/blog/myapp/views/posts/edit.ctp
 <div class="posts form">
 <?php echo $form->create('Post');?>
     <fieldset>
         <legend><?php __('Edit Post');?></legend>
     <?php
         echo $form->input('id');
         echo $form->input('title');
         echo $form->input('body');
     ?>
     </fieldset>
 <?php echo $form->end('Submit');?>
 </div>
 <div class="actions">
     <ul>
         <li><?php echo $html->link(__('Delete', true), array('action'=>'delete', $form->value('Post.id') ), 
         null, sprintf(__('Are you sure you want to delete # %s?', true), $form->value('Post.id'))); ?></li>
         <li><?php echo $html->link(__('List Posts', true), array('action'=>'index'));?></li>
     </ul>
 </div>



*稼働画面 [#gd18a6a9]

&ref(Bake_blog_index画面.JPG);

&ref(Bake_blog_view画面.JPG);

&ref(Bake_blog_edit画面.JPG);


#vote(参考になった[31],ふつう[4],参考にならなかった[4])
#vote(参考になった[32],ふつう[4],参考にならなかった[4])

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS