I've read through Yii2 documentation several times. I also googled and I couldn't find anything useful yet.
The problem is I do not understand the concept of the environment folders. Please let me explain:
Why I have to duplicate all my controllers, views and other files in environment/dev & environment/prod?
In what folders I actually have to make my development?
What the deployment procedure for environment folders? Should I call init every time after I push my changes to production server?
You will most likely ignore the environments folder unless you have a very specific need to do otherwise.
All your code should go into either common
, frontend
, console
, or backend
folders. common
appart, these are the default available entry points to your application, where you will place your controller logic. You obviously don't have to use them all, simply using frontend
could suffice depending on your specific need.
But then again if you chose the advanced template it's probably to use a combination.. like say, common
, backend
and frontend
The environment folders correspond to the options you have when running ./init
. That is to name:
They contain all the files that are edited and/or added when you run the ./init
command. These include all the files that are ignored (and therefore never created) by the VCS (git).
We're talking about files like *-local.php files that for obvious reasons should never be versioned. But also the entry scripts that change depending on the environment you are initializing. For example, you want debugging and logging off when in production, but on in development. These are things you can't set up on the configuration file level as they need to be set before the Yii application mock-up or that you just know will need to be default every time the environment is initialized.
You could imagine adding another environment by the name of pre-production for example that would initialize your application exactly like the production environment except with logging enabled. For this you would copy the environments/prod
folder, modify the entry scripts to your needs, and add the option in environments/index.php
.
The ./init
only needs to be run once after you clone the branch. If you're big on CI then your CI server may need to run the ./init
script on every run. This could depend on how you configured it though. You will need to run it again if you've made changes to the environment folders that you want to apply.
This you probably already know but just incase someone was wondering.
./yii controller/action
This is usually where all the magic happens, no need to duplicate any code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With