1. bakeを使ってベースシステムを作成する(2)
bakeを使えるようになったら、bakeを使ってPHPソースコードを生成して行きます。
2. まずは、Modelを生成します
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
$ /usr/bin/php ./app/Console/cake.php bake Welcome to CakePHP v2.4.10 Console --------------------------------------------------------------- App : app Path: /home/hoge/public_html/usjnews/app/ --------------------------------------------------------------- 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 --------------------------------------------------------------- Bake Model Path: /home/hoge/public_html/usjnews/app/Model/ --------------------------------------------------------------- Use Database Config: (default/test) [default] > Possible Models based on your current database: 1. News 2. Site Enter a number from the list above, type in the name of another model, or 'q' to exit [q] > 1 Would you like to supply validation criteria for the fields in your model? (y/n) [y] > n Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)? (y/n) [y] > One moment while the associations are detected. --------------------------------------------------------------- Please confirm the following associations: --------------------------------------------------------------- News belongsTo Site? (y/n) [y] > Would you like to define some additional model associations? (y/n) [n] > --------------------------------------------------------------- The following Model will be created: --------------------------------------------------------------- Name: News DB Table: `usjnews`.`news` Associations: News belongsTo Site --------------------------------------------------------------- Look okay? (y/n) [y] > Baking model class for News... Creating file /home/hoge/public_html/usjnews/app/Model/News.php Wrote `/home/hoge/public_html/usjnews/app/Model/News.php` Baking test fixture for News... Creating file /home/hoge/public_html/usjnews/app/Test/Fixture/NewsFixture.php Wrote `/home/hoge/public_html/usjnews/app/Test/Fixture/NewsFixture.php` Bake is detecting possible fixtures... Baking test case for News Model ... Creating file /home/hoge/public_html/usjnews/app/Test/Case/Model/NewsTest.php Wrote `/home/hoge/public_html/usjnews/app/Test/Case/Model/NewsTest.php` --------------------------------------------------------------- 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 --------------------------------------------------------------- Bake Model Path: /home/hoge/public_html/usjnews/app/Model/ --------------------------------------------------------------- Possible Models based on your current database: 1. News 2. Site Enter a number from the list above, type in the name of another model, or 'q' to exit [q] > 2 Would you like to supply validation criteria for the fields in your model? (y/n) [y] > n Would you like to define model associations (hasMany, hasOne, belongsTo, etc.)? (y/n) [y] > y One moment while the associations are detected. --------------------------------------------------------------- Please confirm the following associations: --------------------------------------------------------------- Site hasMany News? (y/n) [y] > Would you like to define some additional model associations? (y/n) [n] > n --------------------------------------------------------------- The following Model will be created: --------------------------------------------------------------- Name: Site DB Table: `usjnews`.`site` Associations: Site hasMany News --------------------------------------------------------------- Look okay? (y/n) [y] > y Baking model class for Site... Creating file /home/hoge/public_html/usjnews/app/Model/Site.php Wrote `/home/hoge/public_html/usjnews/app/Model/Site.php` Baking test fixture for Site... Creating file /home/hoge/public_html/usjnews/app/Test/Fixture/SiteFixture.php Wrote `/home/hoge/public_html/usjnews/app/Test/Fixture/SiteFixture.php` Bake is detecting possible fixtures... Baking test case for Site Model ... Creating file /home/hoge/public_html/usjnews/app/Test/Case/Model/SiteTest.php Wrote `/home/hoge/public_html/usjnews/app/Test/Case/Model/SiteTest.php` <h2> 3. Controllerを生成します</h2> <pre> --------------------------------------------------------------- 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) > C --------------------------------------------------------------- Bake Controller Path: /home/hoge/public_html/usjnews/app/Controller/ --------------------------------------------------------------- Use Database Config: (default/test) [default] > Possible Controllers based on your current database: --------------------------------------------------------------- 1. News 2. Sites Enter a number from the list above, type in the name of another controller, or 'q' to exit [q] > 1 --------------------------------------------------------------- Baking NewsController --------------------------------------------------------------- Would you like to build your controller interactively? (y/n) [y] > Would you like to use dynamic scaffolding? (y/n) [n] > Would you like to create some basic class methods (index(), add(), view(), edit())? (y/n) [n] > y Would you like to create the basic class methods for admin routing? (y/n) [n] > n Would you like this controller to use other helpers besides HtmlHelper and FormHelper? (y/n) [n] > Would you like this controller to use other components besides PaginatorComponent? (y/n) [n] > Would you like to use Session flash messages? (y/n) [y] > --------------------------------------------------------------- The following controller will be created: --------------------------------------------------------------- Controller Name: News Components: Paginator, Session --------------------------------------------------------------- Look okay? (y/n) [y] > Baking controller class for News... Creating file /home/hoge/public_html/usjnews/app/Controller/NewsController.php Wrote `/home/hoge/public_html/usjnews/app/Controller/NewsController.php` Bake is detecting possible fixtures... Baking test case for News Controller ... Creating file /home/hoge/public_html/usjnews/app/Test/Case/Controller/NewsControllerTest.php Wrote `/home/hoge/public_html/usjnews/app/Test/Case/Controller/NewsControllerTest.php` --------------------------------------------------------------- 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) > C --------------------------------------------------------------- Bake Controller Path: /home/hoge/public_html/usjnews/app/Controller/ --------------------------------------------------------------- Possible Controllers based on your current database: --------------------------------------------------------------- 1. News 2. Sites Enter a number from the list above, type in the name of another controller, or 'q' to exit [q] > 2 --------------------------------------------------------------- Baking SitesController --------------------------------------------------------------- Would you like to build your controller interactively? (y/n) [y] > Would you like to use dynamic scaffolding? (y/n) [n] > Would you like to create some basic class methods (index(), add(), view(), edit())? (y/n) [n] > y Would you like to create the basic class methods for admin routing? (y/n) [n] > Would you like this controller to use other helpers besides HtmlHelper and FormHelper? (y/n) [n] > Would you like this controller to use other components besides PaginatorComponent? (y/n) [n] > Would you like to use Session flash messages? (y/n) [y] > --------------------------------------------------------------- The following controller will be created: --------------------------------------------------------------- Controller Name: Sites Components: Paginator, Session --------------------------------------------------------------- Look okay? (y/n) [y] > Baking controller class for Sites... Creating file /home/hoge/public_html/usjnews/app/Controller/SitesController.php Wrote `/home/hoge/public_html/usjnews/app/Controller/SitesController.php` Bake is detecting possible fixtures... Baking test case for Sites Controller ... Creating file /home/hoge/public_html/usjnews/app/Test/Case/Controller/SitesControllerTest.php Wrote `/home/hoge/public_html/usjnews/app/Test/Case/Controller/SitesControllerTest.php` |
3. Controllerを生成します
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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
--------------------------------------------------------------- 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) > V --------------------------------------------------------------- Bake View Path: /home/hoge/public_html/usjnews/app/View/ --------------------------------------------------------------- Use Database Config: (default/test) [default] > Possible Controllers based on your current database: --------------------------------------------------------------- 1. News 2. Sites Enter a number from the list above, type in the name of another controller, or 'q' to exit [q] > 1 Would you like bake to build your views interactively? Warning: Choosing no will overwrite News views if it exist. (y/n) [n] > Baking `index` view file... Creating file /home/hoge/public_html/usjnews/app/View/News/index.ctp Wrote `/home/hoge/public_html/usjnews/app/View/News/index.ctp` Baking `view` view file... Creating file /home/hoge/public_html/usjnews/app/View/News/view.ctp Wrote `/home/hoge/public_html/usjnews/app/View/News/view.ctp` Baking `add` view file... Creating file /home/hoge/public_html/usjnews/app/View/News/add.ctp Wrote `/home/hoge/public_html/usjnews/app/View/News/add.ctp` Baking `edit` view file... Creating file /home/hoge/public_html/usjnews/app/View/News/edit.ctp Wrote `/home/hoge/public_html/usjnews/app/View/News/edit.ctp` --------------------------------------------------------------- View Scaffolding Complete. --------------------------------------------------------------- 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) > V --------------------------------------------------------------- Bake View Path: /home/hoge/public_html/usjnews/app/View/ --------------------------------------------------------------- Possible Controllers based on your current database: --------------------------------------------------------------- 1. News 2. Sites Enter a number from the list above, type in the name of another controller, or 'q' to exit [q] > 2 Would you like bake to build your views interactively? Warning: Choosing no will overwrite Sites views if it exist. (y/n) [n] > Baking `index` view file... Creating file /home/hoge/public_html/usjnews/app/View/Sites/index.ctp Wrote `/home/hoge/public_html/usjnews/app/View/Sites/index.ctp` Baking `view` view file... Creating file /home/hoge/public_html/usjnews/app/View/Sites/view.ctp Wrote `/home/hoge/public_html/usjnews/app/View/Sites/view.ctp` Baking `add` view file... Creating file /home/hoge/public_html/usjnews/app/View/Sites/add.ctp Wrote `/home/hoge/public_html/usjnews/app/View/Sites/add.ctp` Baking `edit` view file... Creating file /home/hoge/public_html/usjnews/app/View/Sites/edit.ctp Wrote `/home/hoge/public_html/usjnews/app/View/Sites/edit.ctp` --------------------------------------------------------------- View Scaffolding Complete. --------------------------------------------------------------- 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) > |