Bakeでブログチュートリアルを自動作成してみた
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
閲覧総計:&counter(); (本日:&counter(today); 昨日...
CakePHPには「Bake」という質問に答えていくだけでCakePHPの...
れる便利なツールがある。
早速、先に勉強した「ブログチュートリアル」と同じものをBak...
(参考)
[[ブログチュートリアルをやってみた]]
|&attachref(blog_index画面_0.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\ht...
C:\xampp\htdocs\cake\cake\console>&color(red){php cake.ph...
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 dire...
Example: C:\xampp\htdocs\cakephp\myapp
[C:\xampp\htdocs\cakephp\myapp] > &color(red){C:\xampp\ht...
Bake Project
Skel Directory: C:\xampp\htdocs\cake\cake\console\libs\te...
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\.ht...
pp\htdocs\cakephp\blog2\.htaccess
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\app...
to C:\xampp\htdocs\cakephp\blog2\app_controller.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\app...
:\xampp\htdocs\cakephp\blog2\app_helper.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\app...
\xampp\htdocs\cakephp\blog2\app_model.php
C:\xampp\htdocs\cakephp\blog2\config created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
to C:\xampp\htdocs\cakephp\blog2\config\acl.ini.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
d to C:\xampp\htdocs\cakephp\blog2\config\bootstrap.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
C:\xampp\htdocs\cakephp\blog2\config\core.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
t copied to C:\xampp\htdocs\cakephp\blog2\config\database...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
ied to C:\xampp\htdocs\cakephp\blog2\config\inflections.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
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\con...
ed to C:\xampp\htdocs\cakephp\blog2\config\sql\db_acl.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
ed to C:\xampp\htdocs\cakephp\blog2\config\sql\db_acl.sql
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
to C:\xampp\htdocs\cakephp\blog2\config\sql\i18n.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
to C:\xampp\htdocs\cakephp\blog2\config\sql\i18n.sql
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
pied to C:\xampp\htdocs\cakephp\blog2\config\sql\sessions...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
pied to C:\xampp\htdocs\cakephp\blog2\config\sql\sessions...
C:\xampp\htdocs\cakephp\blog2\controllers created
C:\xampp\htdocs\cakephp\blog2\controllers\components crea...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
er.php copied to C:\xampp\htdocs\cakephp\blog2\controller...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\ind...
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 crea...
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 crea...
C:\xampp\htdocs\cakephp\blog2\tests\cases\controllers cre...
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 cr...
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 c...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
default.ctp copied to C:\xampp\htdocs\cakephp\blog2\views...
fault.ctp
C:\xampp\htdocs\cakephp\blog2\views\elements\email\text c...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
default.ctp copied to C:\xampp\htdocs\cakephp\blog2\views...
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\vie...
ied to C:\xampp\htdocs\cakephp\blog2\views\layouts\ajax.ctp
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\def...
C:\xampp\htdocs\cakephp\blog2\views\layouts\email created
C:\xampp\htdocs\cakephp\blog2\views\layouts\email\html cr...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
efault.ctp copied to C:\xampp\htdocs\cakephp\blog2\views\...
ult.ctp
C:\xampp\htdocs\cakephp\blog2\views\layouts\email\text cr...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
efault.ctp copied to C:\xampp\htdocs\cakephp\blog2\views\...
ult.ctp
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
pied to C:\xampp\htdocs\cakephp\blog2\views\layouts\flash...
C:\xampp\htdocs\cakephp\blog2\views\layouts\js created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
tp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\...
C:\xampp\htdocs\cakephp\blog2\views\layouts\rss created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
ctp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts...
C:\xampp\htdocs\cakephp\blog2\views\layouts\xml created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
ctp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts...
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\web...
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\web...
ss copied to C:\xampp\htdocs\cakephp\blog2\webroot\css\ca...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
C:\xampp\htdocs\cakephp\blog2\webroot\css.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
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\web...
copied to C:\xampp\htdocs\cakephp\blog2\webroot\img\cake....
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
copied to C:\xampp\htdocs\cakephp\blog2\webroot\img\cake....
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
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\web...
ied to C:\xampp\htdocs\cakephp\blog2\webroot\js\vendors.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
C:\xampp\htdocs\cakephp\blog2\webroot\test.php
Creating file C:\xampp\htdocs\cakephp\blog2\views\pages\h...
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 web...
CAKE_CORE_INCLUDE_PATH set to C:\xampp\htdocs\cake in web...
Remember to check these value after moving to production ...
Your database configuration was not found. Take a moment ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Database Configuration:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Name:
[default] >&color(red){↓};
Driver: (db2/firebird/mssql/mysql/mysqli/odbc/oracle/post...
[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 passwor...
[n] > &color(red){y↓};
Database Name:
[cake] > &color(red){blog↓};
Table Prefix?
[n] >&color(red){↓};
Table encoding?
[n] > &color(red){ujis↓}; //通常は「utf8」ですが、私...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
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\databa...
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,30...
●オールグリーなら問題なし。
*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\ht...
C:\xampp\htdocs\cake\cake\console>&color(red){php cake.ph...
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 a...
exit
[q] > &color(red){1↓};
Would you like to supply validation criteria for the fiel...
[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, has...
[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 ...
[y] >&color(red){↓};
You can download the Cake test suite from http://cakeforg...
Baking test fixture for Post...
Creating file C:\xampp\htdocs\cakephp\blog2\tests\fixture...
Wrote C:\xampp\htdocs\cakephp\blog2\tests\fixtures\post_f...
Baking unit test for Post...
Creating file C:\xampp\htdocs\cakephp\blog2\tests\cases\m...
Wrote C:\xampp\htdocs\cakephp\blog2\tests\cases\models\po...
*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 a...
[q] > &color(red){1↓};
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Baking PostsController
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Would you like to build your controller interactively? (y...
[y] >&color(red){↓};
Would you like to use scaffolding? (y/n)
[n] >&color(red){↓};
Would you like to include some basic class methods (index...
[n] > &color(red){y↓};
Would you like to create the methods for admin routing? (...
[n] >&color(red){↓};
Would you like this controller to use other helpers besid...
[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\p...
Wrote C:\xampp\htdocs\cakephp\blog2\controllers\posts_con...
Cake test suite not installed. Do you want to bake unit ...
[y] >&color(red){↓};
You can download the Cake test suite from http://cakeforg...
Baking unit test for Posts...
Creating file C:\xampp\htdocs\cakephp\blog2\tests\cases\c...
Wrote C:\xampp\htdocs\cakephp\blog2\tests\cases\controlle...
*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 a...
[q] > &color(red){1↓};
Would you like to create some scaffolded views (index, ad...
NOTE: Before doing so, you'll need to create your control...
[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\i...
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\index.ctp
Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\v...
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\view.ctp
Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\a...
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\add.ctp
Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\e...
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/にアクセス...
|&attachref(Bake_blog_index画面.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...
}
$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), ar...
} else {
}
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->flash(__('Invalid Post', true), array...
}
if (!empty($this->data)) {
if ($this->Post->save($this->data)) {
$this->flash(__('The Post has been saved...
} else {
}
}
if (empty($this->data)) {
$this->data = $this->Post->read(null, $id);
}
}
function delete($id = null) {
if (!$id) {
$this->flash(__('Invalid Post', true), array...
}
if ($this->Post->del($id)) {
$this->flash(__('Post deleted', true), array...
}
}
}
?>
**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...
%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), arr...
<?php echo $html->link(__('Edit', true), arr...
<?php echo $html->link(__('Delete', true), a...
n ull, sprintf(__('Are you sure you want to ...
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="paging">
<?php echo $paginator->prev('<< '.__('previous', tru...
| <?php echo $paginator->numbers();?>
<?php echo $paginator->next(__('next', true).' >>', ...
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Post', true),...
</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 _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['id']; ?>
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['title']; ?>
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['body']; ?>
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['created']; ?>
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['modified']; ?>
</dd>
</dl>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Edit Post', true)...
<li><?php echo $html->link(__('Delete Post', tru...
null, sprintf(__('Are you sure you want to delet...
<li><?php echo $html->link(__('List Posts', true...
<li><?php echo $html->link(__('New Post', true),...
</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), a...
null, sprintf(__('Are you sure you want to delet...
<li><?php echo $html->link(__('List Posts', true...
</ul>
</div>
*稼働画面 [#gd18a6a9]
&ref(Bake_blog_index画面.JPG);
&ref(Bake_blog_view画面.JPG);
&ref(Bake_blog_edit画面.JPG);
#vote(参考になった[32],ふつう[4],参考にならなかった[4])
終了行:
閲覧総計:&counter(); (本日:&counter(today); 昨日...
CakePHPには「Bake」という質問に答えていくだけでCakePHPの...
れる便利なツールがある。
早速、先に勉強した「ブログチュートリアル」と同じものをBak...
(参考)
[[ブログチュートリアルをやってみた]]
|&attachref(blog_index画面_0.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\ht...
C:\xampp\htdocs\cake\cake\console>&color(red){php cake.ph...
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 dire...
Example: C:\xampp\htdocs\cakephp\myapp
[C:\xampp\htdocs\cakephp\myapp] > &color(red){C:\xampp\ht...
Bake Project
Skel Directory: C:\xampp\htdocs\cake\cake\console\libs\te...
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\.ht...
pp\htdocs\cakephp\blog2\.htaccess
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\app...
to C:\xampp\htdocs\cakephp\blog2\app_controller.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\app...
:\xampp\htdocs\cakephp\blog2\app_helper.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\app...
\xampp\htdocs\cakephp\blog2\app_model.php
C:\xampp\htdocs\cakephp\blog2\config created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
to C:\xampp\htdocs\cakephp\blog2\config\acl.ini.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
d to C:\xampp\htdocs\cakephp\blog2\config\bootstrap.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
C:\xampp\htdocs\cakephp\blog2\config\core.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
t copied to C:\xampp\htdocs\cakephp\blog2\config\database...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
ied to C:\xampp\htdocs\cakephp\blog2\config\inflections.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
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\con...
ed to C:\xampp\htdocs\cakephp\blog2\config\sql\db_acl.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
ed to C:\xampp\htdocs\cakephp\blog2\config\sql\db_acl.sql
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
to C:\xampp\htdocs\cakephp\blog2\config\sql\i18n.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
to C:\xampp\htdocs\cakephp\blog2\config\sql\i18n.sql
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
pied to C:\xampp\htdocs\cakephp\blog2\config\sql\sessions...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
pied to C:\xampp\htdocs\cakephp\blog2\config\sql\sessions...
C:\xampp\htdocs\cakephp\blog2\controllers created
C:\xampp\htdocs\cakephp\blog2\controllers\components crea...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\con...
er.php copied to C:\xampp\htdocs\cakephp\blog2\controller...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\ind...
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 crea...
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 crea...
C:\xampp\htdocs\cakephp\blog2\tests\cases\controllers cre...
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 cr...
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 c...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
default.ctp copied to C:\xampp\htdocs\cakephp\blog2\views...
fault.ctp
C:\xampp\htdocs\cakephp\blog2\views\elements\email\text c...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
default.ctp copied to C:\xampp\htdocs\cakephp\blog2\views...
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\vie...
ied to C:\xampp\htdocs\cakephp\blog2\views\layouts\ajax.ctp
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\def...
C:\xampp\htdocs\cakephp\blog2\views\layouts\email created
C:\xampp\htdocs\cakephp\blog2\views\layouts\email\html cr...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
efault.ctp copied to C:\xampp\htdocs\cakephp\blog2\views\...
ult.ctp
C:\xampp\htdocs\cakephp\blog2\views\layouts\email\text cr...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
efault.ctp copied to C:\xampp\htdocs\cakephp\blog2\views\...
ult.ctp
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
pied to C:\xampp\htdocs\cakephp\blog2\views\layouts\flash...
C:\xampp\htdocs\cakephp\blog2\views\layouts\js created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
tp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts\...
C:\xampp\htdocs\cakephp\blog2\views\layouts\rss created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
ctp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts...
C:\xampp\htdocs\cakephp\blog2\views\layouts\xml created
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\vie...
ctp copied to C:\xampp\htdocs\cakephp\blog2\views\layouts...
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\web...
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\web...
ss copied to C:\xampp\htdocs\cakephp\blog2\webroot\css\ca...
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
C:\xampp\htdocs\cakephp\blog2\webroot\css.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
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\web...
copied to C:\xampp\htdocs\cakephp\blog2\webroot\img\cake....
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
copied to C:\xampp\htdocs\cakephp\blog2\webroot\img\cake....
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
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\web...
ied to C:\xampp\htdocs\cakephp\blog2\webroot\js\vendors.php
C:\xampp\htdocs\cake\cake\console\libs\templates\skel\web...
C:\xampp\htdocs\cakephp\blog2\webroot\test.php
Creating file C:\xampp\htdocs\cakephp\blog2\views\pages\h...
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 web...
CAKE_CORE_INCLUDE_PATH set to C:\xampp\htdocs\cake in web...
Remember to check these value after moving to production ...
Your database configuration was not found. Take a moment ...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Database Configuration:
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Name:
[default] >&color(red){↓};
Driver: (db2/firebird/mssql/mysql/mysqli/odbc/oracle/post...
[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 passwor...
[n] > &color(red){y↓};
Database Name:
[cake] > &color(red){blog↓};
Table Prefix?
[n] >&color(red){↓};
Table encoding?
[n] > &color(red){ujis↓}; //通常は「utf8」ですが、私...
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
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\databa...
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,30...
●オールグリーなら問題なし。
*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\ht...
C:\xampp\htdocs\cake\cake\console>&color(red){php cake.ph...
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 a...
exit
[q] > &color(red){1↓};
Would you like to supply validation criteria for the fiel...
[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, has...
[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 ...
[y] >&color(red){↓};
You can download the Cake test suite from http://cakeforg...
Baking test fixture for Post...
Creating file C:\xampp\htdocs\cakephp\blog2\tests\fixture...
Wrote C:\xampp\htdocs\cakephp\blog2\tests\fixtures\post_f...
Baking unit test for Post...
Creating file C:\xampp\htdocs\cakephp\blog2\tests\cases\m...
Wrote C:\xampp\htdocs\cakephp\blog2\tests\cases\models\po...
*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 a...
[q] > &color(red){1↓};
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Baking PostsController
−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−−
Would you like to build your controller interactively? (y...
[y] >&color(red){↓};
Would you like to use scaffolding? (y/n)
[n] >&color(red){↓};
Would you like to include some basic class methods (index...
[n] > &color(red){y↓};
Would you like to create the methods for admin routing? (...
[n] >&color(red){↓};
Would you like this controller to use other helpers besid...
[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\p...
Wrote C:\xampp\htdocs\cakephp\blog2\controllers\posts_con...
Cake test suite not installed. Do you want to bake unit ...
[y] >&color(red){↓};
You can download the Cake test suite from http://cakeforg...
Baking unit test for Posts...
Creating file C:\xampp\htdocs\cakephp\blog2\tests\cases\c...
Wrote C:\xampp\htdocs\cakephp\blog2\tests\cases\controlle...
*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 a...
[q] > &color(red){1↓};
Would you like to create some scaffolded views (index, ad...
NOTE: Before doing so, you'll need to create your control...
[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\i...
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\index.ctp
Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\v...
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\view.ctp
Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\a...
Wrote C:\xampp\htdocs\cakephp\blog2\views\posts\add.ctp
Creating file C:\xampp\htdocs\cakephp\blog2\views\posts\e...
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/にアクセス...
|&attachref(Bake_blog_index画面.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...
}
$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), ar...
} else {
}
}
}
function edit($id = null) {
if (!$id && empty($this->data)) {
$this->flash(__('Invalid Post', true), array...
}
if (!empty($this->data)) {
if ($this->Post->save($this->data)) {
$this->flash(__('The Post has been saved...
} else {
}
}
if (empty($this->data)) {
$this->data = $this->Post->read(null, $id);
}
}
function delete($id = null) {
if (!$id) {
$this->flash(__('Invalid Post', true), array...
}
if ($this->Post->del($id)) {
$this->flash(__('Post deleted', true), array...
}
}
}
?>
**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...
%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), arr...
<?php echo $html->link(__('Edit', true), arr...
<?php echo $html->link(__('Delete', true), a...
n ull, sprintf(__('Are you sure you want to ...
</td>
</tr>
<?php endforeach; ?>
</table>
</div>
<div class="paging">
<?php echo $paginator->prev('<< '.__('previous', tru...
| <?php echo $paginator->numbers();?>
<?php echo $paginator->next(__('next', true).' >>', ...
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('New Post', true),...
</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 _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['id']; ?>
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['title']; ?>
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['body']; ?>
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['created']; ?>
</dd>
<dt<?php if ($i % 2 == 0) echo $class;?>><?php _...
<dd<?php if ($i++ % 2 == 0) echo $class;?>>
<?php echo $post['Post']['modified']; ?>
</dd>
</dl>
</div>
<div class="actions">
<ul>
<li><?php echo $html->link(__('Edit Post', true)...
<li><?php echo $html->link(__('Delete Post', tru...
null, sprintf(__('Are you sure you want to delet...
<li><?php echo $html->link(__('List Posts', true...
<li><?php echo $html->link(__('New Post', true),...
</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), a...
null, sprintf(__('Are you sure you want to delet...
<li><?php echo $html->link(__('List Posts', true...
</ul>
</div>
*稼働画面 [#gd18a6a9]
&ref(Bake_blog_index画面.JPG);
&ref(Bake_blog_view画面.JPG);
&ref(Bake_blog_edit画面.JPG);
#vote(参考になった[32],ふつう[4],参考にならなかった[4])
ページ名: