CakePHPには便利なコマンドがたくさんありますが、なかなか使いこなせません。
そんな方はまずbakeを使用していみるとよいでしょう。
テーブルを元にして、簡単なindex,add,edit,delete機能のついたControllerとViewとModelを自動で作成してくれます。
これを元に開発するだけで大分効率は変わってくるでしょう。
ModelにはValidate(入力チェック機能)の雛形も付きますので、
必須項目等の効力も入れたテーブルを元にするとなお効果的だと思います。
bakeコマンドで一点だけ注意しなくてはいけないのでモデル名を使用する。ということです。
usersテーブルの場合はUserと先頭大文字の単数形。になります
オプションでallではなくmodelのみやviewのみの指定もできます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | [root@centos100 app] # ./Console/cake bake all User Welcome to CakePHP v2.3.10 Console --------------------------------------------------------------- App : app Path: /var/www/html/sms/app/ --------------------------------------------------------------- Bake All --------------------------------------------------------------- Baking model class for User... Creating file /var/www/html/sms/app/Model/User .php Wrote ` /var/www/html/sms/app/Model/User .php` PHPUnit is not installed. Do you want to bake unit test files anyway? (y /n ) [y] > n Baking controller class for Users... Creating file /var/www/html/sms/app/Controller/UsersController .php Wrote ` /var/www/html/sms/app/Controller/UsersController .php` PHPUnit is not installed. Do you want to bake unit test files anyway? (y /n ) [y] > n Baking `index` view file ... Creating file /var/www/html/sms/app/View/Users/index .ctp Wrote ` /var/www/html/sms/app/View/Users/index .ctp` Baking `view` view file ... Creating file /var/www/html/sms/app/View/Users/view .ctp Wrote ` /var/www/html/sms/app/View/Users/view .ctp` Baking `add` view file ... Creating file /var/www/html/sms/app/View/Users/add .ctp Wrote ` /var/www/html/sms/app/View/Users/add .ctp` Baking `edit` view file ... Creating file /var/www/html/sms/app/View/Users/edit .ctp Wrote ` /var/www/html/sms/app/View/Users/edit .ctp` Bake All complete [root@centos100 app] # |