When installing the basic version of Yii2, you will see the following directory structure:
There is a second assets folder under web. This folder is used by Yii as a cache for the assets. You need not concern yourself with this folder. If you are using git as version control repository, you will notice .gitignore is in that second assets folder. Nothing in that folder should be committed to the repository.
The commands directory allows you to create Yii management scripts that run under command line. You execute these commands by navigating to the Yii root folder in command line terminal and typing php yii or just ./yii. If you type either of those by themselves in a command line environment, you will get a list of commands that are available by default.
In the basic template, there is one example included that you can access through command line like this:
php yii hello
That will output ‘Hello World’ to your terminal.
This folder holds the configuration files that include things like connecting Yii with your database, setting up e-mail sending, reformatting URLs and setting globally available parameter values.
‘C’ of MVC. Controllers are the heart of Yii. Controllers are the traffic directors of an MVC framework. When you make a web request to a Yii powered site, the controller is what processes that request.
The mail folder contains the templates that Yii uses to construct an e-mail message.
‘M’ of MVC. The models folder is where all the database functionality goes. If you need to query the database or perform any other database manipulation, the code will go in the models folder.
The runtime folder is used by Yii when processing web requests. It needs to be writable and should be excluded from any Git repository (you will see a .gitignore file in this directory). You can safely ignore this directory.
The tests folder is set up to facilitate functional testing using Codeception.
This directory is where the Yii source files reside. It is also where any additional third party modules that you install will be included. It is generally a very bad idea to alter the code in the vendor directory. The reason being that when you run any upgrades, the customized code you created will be overwritten.
The upgrade process is very easy using Composer. In command line terminal while in the Yii directory enter the following:
composer require yiisoft/yii2 2.0.6
(2.0.6 is the current version as of this writing.)
To update all third party plugins installed via Composer, execute the following command:
‘V’ of MVC. The views folder holds the pages that are displayed upon a web request. These files contain the HTML markup that renders the pages that display the queried data.
This is the document root directory that the web server points to. The primary function is index.php, which launches the Yii processes when called. Note that in this file, you can turn on or off the Yii debugging code. This enables the debug bar viewable at the bottom of the page, as mentioned in section 3.7.3.
You can set the Yii environment to ‘dev’ or ‘prod’ in the index.php file as well.
This folder is where you would put any files, images or other assets that you want to be accessible from the web. Only files in this folder can be accessed. You may want to have the following subdirectories:
Containing all external style sheets.
All images to be used in any views.
There is one other subdirectory that you will find under web: assets. Like runtime, this directory is for use by Yii when responding to web requests. It needs to be writable by Yii and you can safely ignore it. This directory should also be excluded from any Git repo (hence the .gitignore file).