Yii2高级模板的安装

1.通过composer 安装高级版

 

  1. C:wampwwwyii>composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced  

 

 

2. 进入 advanced 目录中 执行 init 初始化

 

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


高级应用程序几乎完成。您可以访问已创建的各种页面,但如果您尝试登录到该网站或创建一个用户,您可能会遇到这样的错误。

 

 

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


为高级应用程序创建数据库,配置数据信息即可解决上面问题

 

 

  1. mysql> create database yii2advanced;  
  2. Query OK, 1 row affected (0.01 sec)  


修改数据库配置信息 打开文件 common/config/main-local.php

 

 

  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 命令

 

 

  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.   
  7. Apply the above migration? (yes|no) [no]:y  
  8. *** applying m130524_201442_init  
  9. > create table {{%user}} … done (time: 0.031s)  
  10. *** applied m130524_201442_init (time: 0.055s)  
  11.   
  12. Migrated up successfully.  



 

高级应用程序模板现在是全功能。这个安装和基本安装有很大的区别。主要的不同点是,先进的模板有三个入口点的应用程序。这将是前端,后端,和控制台。除此之外,还有一个全新的目录结构,你需要熟悉。(此处略过了)

Yii2的高级应用程序模板,主要分 前台 、后台、console 等三部分功能模块 

配置自定义域名 就要分前后台

 

  1. 127.0.0.1 yiiadvanced.com  
  2. 127.0.0.1 admin.yiiadvanced.com  

 

 

配置虚拟主机  httpd-vhosts.conf 

  1. DocumentRoot “C:/wamp/www/yii/advanced/frontend/web”  
  2. ServerName yiiadvanced.com  
  3.   
  4. DocumentRoot “C:/wamp/www/yii/advanced/backend/web”  
  5. ServerName admin.yiiadvanced.com  


重启完毕 访问

http://yiiadvanced.com 前台

http://admin.yiiadvanced.com   后台

posted @ 2015-09-07 15:08  tiandi2050  阅读(500)  评论(0编辑  收藏  举报