1. 程式人生 > >如何 安裝Yii2的高級應用程序模板

如何 安裝Yii2的高級應用程序模板

tle sport *** 程序模板 too sqlstate body app roo

通過composer 安裝高級版

[php] view plain copy
  1. C:wampwwwyii>composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced

2. 進入 advanced 目錄中 執行 init 初始化

[php] view plain copy
  1. C:wampwwwyii>cd advanced
  2. C:wampwwwyiiadvanced>init
  3. Yii Application Initialization Tool v1.0
  4. Which environment do you want the application to be initialized in?
  5. [0] Development
  6. [1] Production
  7. Your choice [0-1, or “q” to quit] 0
  8. Initialize the application under ‘Development’ environment? [yes|no] y
  9. Start initialization …
  10. generate backend/config/main-local.php
  11. generate backend/config/params-local.php
  12. generate backend/web/index-test.php
  13. generate backend/web/index.php
  14. generate common/config/main-local.php
  15. generate common/config/params-local.php
  16. generate console/config/main-local.php
  17. generate console/config/params-local.php
  18. generate frontend/config/main-local.php
  19. generate frontend/config/params-local.php
  20. generate frontend/web/index-test.php
  21. generate frontend/web/index.php
  22. generate yii
  23. generate cookie validation key in backend/config/main-local.php
  24. generate cookie validation key in frontend/config/main-local.php
  25. chmod 0777 backend/runtime
  26. chmod 0777 backend/web/assets
  27. chmod 0777 frontend/runtime
  28. chmod 0777 frontend/web/assets
  29. chmod 0755 yii
  30. … initialization completed.


高級應用程序幾乎完成。您可以訪問已創建的各種頁面,但如果您嘗試登錄到該網站或創建一個用戶,您可能會遇到這樣的錯誤。

[php] view plain copy
  1. Database Exception – yiidbException
  2. SQLSTATE[HY000] [1049] Unknown database ‘yii2advanced’
  3. ?
  4. Caused by: PDOException
  5. SQLSTATE[HY000] [1049] Unknown database ‘yii2advanced’


為高級應用程序創建數據庫,配置數據信息即可解決上面問題

[php] view plain copy
  1. mysql> create database yii2advanced;
  2. Query OK, 1 row affected (0.01 sec)


修改數據庫配置信息 打開文件 common/config/main-local.php

[php] view plain copy
  1. <?php
  2. return [
  3. ‘components‘ => [
  4. ‘db‘ => [
  5. ‘class‘ => ‘yiidbConnection‘,
  6. ‘dsn‘ => ‘mysql:host=localhost;dbname=yii2advanced‘,
  7. ‘username‘ => ‘root‘,
  8. ‘password‘ => ‘‘,
  9. ‘charset‘ => ‘utf8‘,
  10. ],
  11. ‘mailer‘ => [
  12. ‘class‘ => ‘yiiswiftmailerMailer‘,
  13. ‘viewPath‘ => ‘@common/mail‘,
  14. // send all mails to a file by default. You have to set
  15. // ‘useFileTransport‘ to false and configure a transport
  16. // for the mailer to send real emails.
  17. ‘useFileTransport‘ => true,
  18. ],
  19. ],
  20. ];


到此為止我們配置好了 數據庫聯系信息 以及數據庫,但是我們還沒有表,我們使用 yii migrate 命令

[php] view plain copy
  1. C:wampwwwyiiadvanced>yii migrate
  2. Yii Migration Tool (based on Yii v2.0.0)
  3. Creating migration history table “migration”…done.
  4. Total 1 new migration to be applied:
  5. m130524_201442_init
  6. Apply the above migration? (yes|no) [no]:y
  7. *** applying m130524_201442_init
  8. > create table {{%user}} … done (time: 0.031s)
  9. *** applied m130524_201442_init (time: 0.055s)
  10. Migrated up successfully.



高級應用程序模板現在是全功能。這個安裝和基本安裝有很大的區別。主要的不同點是,先進的模板有三個入口點的應用程序。這將是前端,後端,和控制臺。除此之外,還有一個全新的目錄結構,你需要熟悉。(此處略過了)

Yii2的高級應用程序模板,主要分 前臺 、後臺、console 等三部分功能模塊

配置自定義域名 就要分前後臺

[php] view plain copy
  1. 127.0.0.1 yiiadvanced.com
  2. 127.0.0.1 admin.yiiadvanced.com

配置虛擬主機 httpd-vhosts.conf

[php] view plain copy
  1. DocumentRoot “C:/wamp/www/yii/advanced/frontend/web”
  2. ServerName yiiadvanced.com
  3. DocumentRoot “C:/wamp/www/yii/advanced/backend/web”
  4. ServerName admin.yiiadvanced.com


重啟完畢 訪問

http://yiiadvanced.com 前臺

http://admin.yiiadvanced.com 後臺

如何 安裝Yii2的高級應用程序模板