如何 安裝Yii2的高級應用程序模板
阿新 • • 發佈:2017-12-27
tle sport *** 程序模板 too sqlstate body app roo
通過composer 安裝高級版
[php] view plain copy
- C:wampwwwyii>composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced
2. 進入 advanced 目錄中 執行 init 初始化
[php] view plain copy
- C:wampwwwyii>cd advanced
- C:wampwwwyiiadvanced>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] y
- 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
- … initialization completed.
高級應用程序幾乎完成。您可以訪問已創建的各種頁面,但如果您嘗試登錄到該網站或創建一個用戶,您可能會遇到這樣的錯誤。
[php] view plain copy
- Database Exception – yiidbException
- SQLSTATE[HY000] [1049] Unknown database ‘yii2advanced’
- ?
- Caused by: PDOException
- SQLSTATE[HY000] [1049] Unknown database ‘yii2advanced’
為高級應用程序創建數據庫,配置數據信息即可解決上面問題
[php] view plain copy
- mysql> create database yii2advanced;
- Query OK, 1 row affected (0.01 sec)
修改數據庫配置信息 打開文件 common/config/main-local.php
[php] view plain copy
- <?php
- return [
- ‘components‘ => [
- ‘db‘ => [
- ‘class‘ => ‘yiidbConnection‘,
- ‘dsn‘ => ‘mysql:host=localhost;dbname=yii2advanced‘,
- ‘username‘ => ‘root‘,
- ‘password‘ => ‘‘,
- ‘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,
- ],
- ],
- ];
到此為止我們配置好了 數據庫聯系信息 以及數據庫,但是我們還沒有表,我們使用 yii migrate 命令
[php] view plain copy
- C:wampwwwyiiadvanced>yii migrate
- Yii Migration Tool (based on Yii v2.0.0)
- Creating migration history table “migration”…done.
- Total 1 new migration to be applied:
- m130524_201442_init
- Apply the above migration? (yes|no) [no]:y
- *** applying m130524_201442_init
- > create table {{%user}} … done (time: 0.031s)
- *** applied m130524_201442_init (time: 0.055s)
- Migrated up successfully.
高級應用程序模板現在是全功能。這個安裝和基本安裝有很大的區別。主要的不同點是,先進的模板有三個入口點的應用程序。這將是前端,後端,和控制臺。除此之外,還有一個全新的目錄結構,你需要熟悉。(此處略過了)
Yii2的高級應用程序模板,主要分 前臺 、後臺、console 等三部分功能模塊
配置自定義域名 就要分前後臺
[php] view plain copy
- 127.0.0.1 yiiadvanced.com
- 127.0.0.1 admin.yiiadvanced.com
配置虛擬主機 httpd-vhosts.conf
[php] view plain copy- DocumentRoot “C:/wamp/www/yii/advanced/frontend/web”
- ServerName yiiadvanced.com
- DocumentRoot “C:/wamp/www/yii/advanced/backend/web”
- ServerName admin.yiiadvanced.com
重啟完畢 訪問
http://yiiadvanced.com 前臺
http://admin.yiiadvanced.com 後臺
如何 安裝Yii2的高級應用程序模板