通过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 后台
原文地址:https://www.cnblogs.com/haha2016/p/8124806.html
时间: 2024-11-14 12:38:47