yii2-app-advanced
Yii2 要求 PHP 版本在 PHP 5.4.0 之上
eg. yii2 中用到這樣的代碼 php 5.3.5 就不支持
$extension = ['name' => $package->getName(),'version' => $package->getVersion(),];
如果之前使用的是 PHP5.3 版本 要切換到 PHP5.4, 可以參考我的另一篇筆記
php5.3 php5.4 install and config on windows VC6 and VC9
原創文章 http://www.49028c.com/ganiks/
下面對 yii2 的 2 種模板分別進行 Install 和 RunInstall Yii2 advanced via ComposerIf you do not have Composer, you may install it by following the instructions at getcomposer.org.
C:/Documents and Settings/ganiks.liu>php -vPHP 5.4.30 (cli) (built: Jun 25 2014 18:06:41)Copyright (c) 1997-2014 The PHP GroupZend Engine v2.4.0, Copyright (c) 1998-2014 Zend TechnologiesC:/Documents and Settings/ganiks.liu>e:E:/>composer create-PRoject --prefer-dist --stability=dev yiisoft/yii2-app-advanced advancedInstalling yiisoft/yii2-app-advanced (dev-master f7e31c08c47124bda8fecd596d94f3dc4c1d5218) - Installing yiisoft/yii2-app-advanced (dev-master master) Downloading: 100%Created project in advancedLoading composer repositories with package informationInstalling dependencies (including require-dev) - Installing ezyang/htmlpurifier (v4.6.0) Downloading: 100% - Installing swiftmailer/swiftmailer (dev-master 1471619) Downloading: 100% - Installing yiisoft/jquery (2.1.1) Downloading: 100% - Installing yiisoft/jquery-pjax (dev-master 520f8c1) Downloading: 100% - Installing cebe/markdown (0.9.x-dev 6a3c373) Downloading: 100% - Installing yiisoft/yii2-composer (dev-master e5614b1) Downloading: 100% - Installing yiisoft/yii2 (dev-master e8e1e41) Downloading: 100% - Installing phpspec/php-diff (dev-master 30e103d) Downloading: 100% - Installing yiisoft/yii2-swiftmailer (dev-master afd6982) Downloading: 100% - Installing yiisoft/yii2-codeception (dev-master 397b494) Downloading: 100% - Installing twbs/bootstrap (dev-master 36483af) Downloading: 100% - Installing yiisoft/yii2-bootstrap (dev-master b74f3b0) Downloading: 100% - Installing yiisoft/yii2-debug (dev-master 403ca66) Downloading: 100% - Installing yiisoft/yii2-gii (dev-master c50b66b) Downloading: 100%Writing lock fileGenerating autoload filesSetting writable: backend/runtime ...doneSetting writable: backend/web/assets ...doneSetting writable: frontend/runtime ...doneSetting writable: frontend/web/assets ...doneE:/>
至此, Yii2 Advanced 模板框架已經安裝完畢
Init Yii2 Project進入到 /path/to/yii-application
, 在 cmd 命令下執行 init 命令
E:/yii2advanced>initYii Application Initialization Tool v1.0Which 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] yes 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.
Config your Apache2 Web Server<VirtualHost *:80> DocumentRoot "E:/yii2advanced/backend/web" DirectoryIndex index.php ServerName yii2back </VirtualHost><Directory "E:/yii2advanced/backend/web"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all</Directory><VirtualHost *:80> DocumentRoot "E:/yii2advanced/frontend/web" DirectoryIndex index.php ServerName yii2front </VirtualHost><Directory "E:/yii2advanced/frontend/web"> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all</Directory>
also config your windows hosts
127.0.0.1 yii2front127.0.0.1 yii2back
Migrate DB現在已經可以訪問 http://yii2front
or http://yii2back
來訪問項目了
不錯, Yii2 已經默認開啟了 Bootstrap 界面,很清爽
此時我們還沒有配置 DB, 當然沒有辦法 Login or SignUp
首先當然是要建立一個 database , 并且 adjust the components['db'] configuration in common/config/main-local.php accordingly.
再來migrate
進入到 /path/to/yii-application
, 在 cmd 命令下執行 migrate 命令
yii migrateE:/yii2advanced>yii migrateYii Migration Tool (based on Yii v2.0.0-dev)Creating migration history table "migration"...done.Total 1 new migration to be applied: m130524_201442_initApply the above migration? (yes|no) [no]:yes*** applying m130524_201442_init > create table {{%user}} ... done (time: 0.078s)*** applied m130524_201442_init (time: 0.124s)Migrated up successfully.
SignUp a user登錄后臺或者前臺之前, 先去 前臺注冊一個用戶, 再登錄
Official DocsYii2 完全托管在 GitHub 上, 因此文檔的翻譯工作貌似會很不錯, 可惜現在只是發布了很少一部分
https://github.com/yiisoft/yii2/tree/master/docs/guide-zh-CN
期待快點更新
后來又發現一個倉庫更新稍快些
https://github.com/yii2-chinesization/yii2-zh-cn/blob/master/guide-zh-CN/README.md
當然英文的文檔已經很全了,可以直接看 官方的 Guide
Install Yii2 app via ComposerE:/>composer create-project --prefer-dist --stability=dev yiisoft/yii2-app-basic yii2app
yii2 的 basic 模板 yii2app 不需要 init 項目, 默認的 login 用戶為 demo 和 admin
新聞熱點
疑難解答