昨日はBasicなテンプレートをインストールしたが、今日はAdvancedなテンプレートをインストールしてみる。
こちらを参考に、昨日と違うコマンドを実行。
$ composer create-project –prefer-dist yiisoft/yii2-app-advanced yii-advanced
Installing yiisoft/yii2-app-advanced (2.0.4)
– Installing yiisoft/yii2-app-advanced (2.0.4)
Downloading: 100%
Created project in yii
Loading composer repositories with package information
Installing dependencies (including require-dev)
– Installing yiisoft/yii2-composer (2.0.3)
Loading from cache
– Installing ezyang/htmlpurifier (v4.6.0)
Loading from cache
– Installing cebe/markdown (1.1.0)
Loading from cache
– Installing bower-asset/jquery (2.1.4)
Loading from cache
– Installing bower-asset/jquery.inputmask (3.1.63)
Loading from cache
– Installing bower-asset/punycode (v1.3.2)
Loading from cache
– Installing bower-asset/yii2-pjax (v2.0.4)
Loading from cache
– Installing yiisoft/yii2 (2.0.4)
Loading from cache
– Installing swiftmailer/swiftmailer (v5.4.1)
Downloading: 100%
– Installing yiisoft/yii2-swiftmailer (2.0.4)
Loading from cache
– Installing yiisoft/yii2-codeception (2.0.4)
Loading from cache
– Installing bower-asset/bootstrap (v3.3.4)
Loading from cache
– Installing yiisoft/yii2-bootstrap (2.0.4)
Loading from cache
– Installing yiisoft/yii2-debug (2.0.4)
Loading from cache
– Installing bower-asset/typeahead.js (v0.10.5)
Loading from cache
– Installing phpspec/php-diff (v1.0.2)
Loading from cache
– Installing yiisoft/yii2-gii (2.0.4)
Loading from cache
– Installing fzaninotto/faker (v1.5.0)
Loading from cache
– Installing yiisoft/yii2-faker (2.0.3)
Loading from cache
fzaninotto/faker suggests installing ext-intl (*)
Writing lock file
Generating autoload files
次にアプリケーションの初期化。因みに開発環境での初期化。
$ php yii-advanced/init
Yii Application Initialization Tool v1.0
Which environment do you want the application to be initialized in?
[0] Development
[1] Production
Your choice [0-1, or “q” to quit] 0
Initialize the application under ‘Development’ environment? [yes|no] yes
Start initialization …
generate backend/config/main-local.php
generate backend/config/params-local.php
generate backend/web/index-test.php
generate backend/web/index.php
generate common/config/main-local.php
generate common/config/params-local.php
generate console/config/main-local.php
generate console/config/params-local.php
generate frontend/config/main-local.php
generate frontend/config/params-local.php
generate frontend/web/index-test.php
generate frontend/web/index.php
generate yii
generate cookie validation key in backend/config/main-local.php
generate cookie validation key in frontend/config/main-local.php
chmod 0777 backend/runtime
chmod 0777 backend/web/assets
chmod 0777 frontend/runtime
chmod 0777 frontend/web/assets
chmod 0755 yii
chmod 0755 tests/codeception/bin/yii
… initialization completed.
あとは、MySQLのデータベースを作成し、その内容でPHPファイルを更新。
$ vi yii-advanced/common/config/main-local.php
return [
‘components’ => [
‘db’ => [
‘class’ => ‘yiidbConnection’,
‘dsn’ => ‘mysql:host=127.0.0.1;port=8889;dbname=yii’,
‘username’ => ‘yii’,
‘password’ => ‘yii’,
‘charset’ => ‘utf8’,
],
‘mailer’ => [
‘class’ => ‘yiiswiftmailerMailer’,
‘viewPath’ => ‘@common/mail’,
// send all mails to a file by default. You have to set
// ‘useFileTransport’ to false and configure a transport
// for the mailer to send real emails.
‘useFileTransport’ => true,
],
],
];
今回は、MAMPを利用しているので、ポートが8889となっている。
データベース名は、yii。
ユーザもyii。
あと、hostはlocalhostだと、migration時に次の様なエラーになるため、127.0.0.1に変更しておく。
Exception ‘yiidbException’ with message ‘SQLSTATE[HY000] [2002] No such file or directory’
in yii/vendor/yiisoft/yii2/db/Connection.php:534
情報を元に、データベースの初期構成を行ってもらう。
$ php yii-advanced/yii migrate
Yii Migration Tool (based on Yii v2.0.4)
Creating migration history table “migration”…Done.
Total 1 new migration to be applied:
m130524_201442_init
Apply the above migration? (yes|no) [no]:yes
*** applying m130524_201442_init
> create table {{%user}} … done (time: 0.019s)
*** applied m130524_201442_init (time: 0.025s)
Migrated up successfully.
これで次のURLでフロントエンド、バックエンドのページが表示される。
http://localhost:8888/yii-advanced/frontend/web/index.php
http://localhost:8888/yii-advanced/backend/web/index.php
落とし穴いっぱい。疲れるよ。