Yii 2.X高級版本項目的安裝
安裝Yii 2.x版本
使用 composer 安裝
composer global require "fxp/composer-asset-plugin"
composer create-project yiisoft/yii2-app-advanced advanced
安裝之後目錄初認識
backend
common
console
environments
frontend
vagrant
vendor
其中backend以及fontend爲項目目錄,其他皆爲配置或者插件目錄,這裏暫時不做介紹
入口文件缺失
理論上來講入口文件爲 backend\web 或者 frontend\web 下面 index.php 文件,但是兩者都不存在
創建入口文件
進入項目根目錄
執行命令: php init
之後一直輸入: yes 回車
查看入口文件
配置網站訪問
這裏使用PHPstudy進行配置
配置數據庫
打開 common\config\main-local.php 文件,我們看到 components 下面的db配置
<?php
return [
'components' => [
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=數據庫名',
'username' => '數據庫用戶名',
'password' => '數據庫用戶密碼',
'charset' => 'utf8',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'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,
],
],
];