问题
What does php init
command actually do?
When I run this command in cmd after creating my project using this command: composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced
I see many files generated in different locations like common, backend, frontend.
`some@user:/var/www/html/yiiapp$ php 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] yes
Start initialization ...
exist common/config/main-local.php
...overwrite? [Yes|No|All|Quit] All
overwrite common/config/main-local.php
unchanged common/config/params-local.php
unchanged yii
overwrite backend/config/main-local.php
unchanged backend/config/params-local.php
unchanged backend/web/index-test.php
unchanged backend/web/index.php
unchanged api/web/index-test.php
unchanged api/web/index.php
overwrite frontend/config/main-local.php
unchanged frontend/config/params-local.php
unchanged frontend/web/index-test.php
unchanged frontend/web/index.php
unchanged console/config/main-local.php
unchanged console/config/params-local.php
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
chmod 0755 tests/codeception/bin/yii
... initialization completed.`
回答1:
init command just copy files from directory /environments to your project
In advanced application you have two environments by default (dev and prod), each environment have different configuration for project.
In each location you have some configuration files main.php, params.php, main-local.php, params-local.php. Files main.php and params.php are common for all environments, and files main-local.php and params-local.php are configurations for current environment.
For example you have database for real project, and database for test purpose. In this case you should write different configurations for db component in files main-local.php and params-local.php.
One more thing about this files. If you want to enable your configuration to project you should rewrite them in directory /environment. Because all *-local.php files included into git-ignore section. So you can test different configuration in /frontend/config/main-local.php file and if you succes with it you can add it to /envinronment/prod/frontend/main-local.php
回答2:
1) Generate config files for all the apps. Backend is an app and frontend is anohter app. With main and main-local you could have different settings in your local and your server for example. Common is for needs for both apps (user model, or a third-party used in both apps, ....).
The template includes three tiers: front end, back end, and console, each of which is a separate Yii application.
From Advanced template installation guide: https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/README.md
2) Also adds permissions for the folders of each app. Example:
'backend/runtime',
'backend/web/assets',
'frontend/runtime',
'frontend/web/assets',
Check the differences between basic and advanced templates here: https://github.com/yiisoft/yii2-app-advanced/blob/master/docs/guide/start-comparison.md
来源:https://stackoverflow.com/questions/36791824/yii2-php-init-command