Yii2环境文件夹的点
我正在尝试解决环境文件夹的重点.
I am trying to work what the point of the environments folder is.
最初我有一个想法,您可以将网络服务器指向 environment
文件夹中不同的 dev
和 prod
文件夹,但在阅读之后我有点意识到事实并非如此.
Originally I had the idea that you could point the webserver to the different dev
and prod
folders in the environment
folder but after reading up a bit I realise this is not the case.
在 Yii 1 中,您只需拥有多个 index.php
即可解决此问题,即:
In Yii 1 you would solve this by just having multiple index.php
's i.e.:
index.php
index-local.php
那么问题是这种新的环境结构实际上给我带来了什么好处,而不是旧的方式?
So the question is what benefit does this new environment structure actually give me over the old way?
我发现环境非常有用,它允许我为多个客户端项目(基于 Yii App Advanced)保留一个公共代码库并设置不同的环境对于每个特定的客户,保持他们的自定义代码私有和独立.
I've found environments very useful in allowing me to keep a common code base for multiple client projects (based on Yii App Advanced) and setting up a different environment for each specific client, keeping their custom code private and separate.
为此,我将环境文件夹与其余代码存储在一个单独的 git 存储库中,并在客户端/项目的基础上下拉相关文件夹.
To do this I store the environments folder in a separate git repo from the rest of the code and pull down the relevant folder on a client/project basis.
这让我可以为所有项目使用基本通用代码,并为特定客户端或项目添加/覆盖任何文件,同时仍然允许单独的开发/生产配置设置.如果客户也使用其他开发人员,他们也会得到满足.这样,只有我选择的公共代码才会在客户端之间共享,而自定义代码将保密.
This lets me use a base common code for all projects and add/override any file for a specific client or project whilst still allowing separate dev/prod config settings. If the client uses other developers too, they are also catered for. In this way, only common code I choose will be shared amongst clients and custom code will be kept private.
我还将 composer.json 文件移动到了环境文件夹中,这样我就可以为每个客户端/项目引入不同的扩展,同时保持这些扩展的私密性.
I've also moved the composer.json file into the environments folder so I can pull in different extensions per client/project keeping those private too.
该 init 命令可以是一个非常强大的工具,您不必局限于核心开发人员提供的模板.
That init command can be a very powerful tool and you don't have to limit yourself to the template provided by the core developers.
如果您不需要环境,那么就不要使用它们,但我向您保证,有些人会发现它非常有用.
If you don't need environments, then don't use them, but I assure you some people will find it very useful.