Yii2 php init 命令 [英] Yii2 php init command

查看:20
本文介绍了Yii2 php init 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

php init 命令实际上做了什么?

What does php init command actually do?

当我在使用此命令创建项目后在 cmd 中运行此命令时:composer create-project --prefer-dist yiisoft/yii2-app-advanced advanced

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.`

推荐答案

init 命令只是将文件从/environments 目录复制到您的项目

init command just copy files from directory /environments to your project

在高级应用程序中,您默认有两个环境(dev 和 prod),每个环境都有不同的项目配置.

In advanced application you have two environments by default (dev and prod), each environment have different configuration for project.

在每个位置都有一些配置文件 main.php、params.php、main-local.php、params-local.php.文件 main.php 和 params.php 是所有环境通用的,文件 main-local.php 和 params-local.php 是当前环境的配置.

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.

例如,您有用于实际项目的数据库,以及用于测试目的的数据库.在这种情况下,您应该在文件 main-local.php 和 params-local.php 中为 db 组件编写不同的配置.

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.

关于这个文件的另一件事.如果您想让您的配置进行投影,您应该在目录/environment 中重写它们.因为所有 *-local.php 文件都包含在 git-ignore 部分中.所以你可以在/frontend/config/main-local.php 文件中测试不同的配置,如果你成功了,你可以将它添加到/envinronment/prod/frontend/main-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

这篇关于Yii2 php init 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆