Motomichi Works Blog

モトミチワークスブログです。その日学習したことについて書いている日記みたいなものです。

vagrantその19-32 cakephp入門をやってみる(bakeによる高速開発その2)Database Configurationの作成

参考にさせていただいたページ

bakeによる高速開発(2/8):初心者のためのCakePHP2.0 プログラミング入門

環境

./cake bakeを実行する

前回の記事で./cake bakeを実行するところまではできた。

実行結果として

Welcome to CakePHP v2.6.1 Console
---------------------------------------------------------------
App : app
Path: /Users/motomichishigeru/Desktop/all/git_repos_all/bitbucket/motomichi_mti/bp_20140708/0003-cakephp/bake/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) 
>

と表示された。

Database Configuration

D

を入力してenterを押下すると、参考ページのような感じになった。

---------------------------------------------------------------
Database Configuration:
---------------------------------------------------------------
Name:  
[default] >

これはNameを設定するらしいのだけど、何も入力せずにenterを押下すると、defaultというNameが 設定されるという意味だそうです。

とりあえずそのままenterを押下して、次に進んでみる。

---------------------------------------------------------------
Database Configuration:
---------------------------------------------------------------
Name:  
[default] > 
Datasource: (Mysql/Postgres/Sqlite/Sqlserver) 
[Mysql] > 
Persistent Connection? (y/n) 
[n] > n
Database Host:  
[localhost] > 
Port?  
[n] > 
User:  
[root] > 
Password:  
> password
Database Name:  
[cake] > 
Table Prefix?  
[n] > n
Table encoding?  
[n] > n

---------------------------------------------------------------
The following database configuration will be created:
---------------------------------------------------------------
Name:         default
Datasource:   Mysql
Persistent:   false
Host:         localhost
User:         root
Pass:         ********
Database:     cake
---------------------------------------------------------------
Look okay? (y/n) 
[y] > y
Do you wish to add another database configuration?  
[n] > n

File `/Users/motomichishigeru/Desktop/all/git_repos_all/bitbucket/motomichi_mti/bp_20140708/0003-cakephp/bake/app/Config/database.php` exists
Do you want to overwrite? (y/n/q) 
[n] > y
Wrote `/Users/motomichishigeru/Desktop/all/git_repos_all/bitbucket/motomichi_mti/bp_20140708/0003-cakephp/bake/app/Config/database.php`

こんな感じで入力して、

これでokですか?

既にdatabase.phpがあるけど上書きして良いですか?

と聞かれたのでyesで。

database.phpを確認してみる

こんな感じにdatabase.phpが作成された。

<?php
class DATABASE_CONFIG {

  public $test = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'user',
    'password' => 'password',
    'database' => 'test_database_name',
  );
  public $default = array(
    'datasource' => 'Database/Mysql',
    'persistent' => false,
    'host' => 'localhost',
    'login' => 'root',
    'password' => 'password',
    'database' => 'cake',
  );
}

インタラクティブBakeシェルについて

さっき表示されたこれのこと

---------------------------------------------------------------
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) 
>

とりあえず今回はここまで。