Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The point of Yii2 environments folder

Tags:

php

yii

yii2

I am trying to work what the point of the environments folder is.

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.

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?

like image 700
Sammaye Avatar asked Jan 23 '14 10:01

Sammaye


1 Answers

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.

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.

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.

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.

like image 120
AngelCoding Avatar answered Sep 28 '22 05:09

AngelCoding