Yii Structure

Yii2 has a new and improved application structure. It uses composer to manage its dependencies. Yii1 has only a basic application structure. While Yii2 has basic as well as advanced application structure.

Yii2 divides the entire application into following sections:

  • Backend : For backend web development
  • Common : Include common files for all the application
  • Console : Console application
  • Environments : Environment configurations
  • Frontend : For frontend web development

Yii2 Directory Structure

assets

Asset bundles are used to include JavaScript and style sheets. Lot of assessment and caching is done through the assets.

There is one more asset folder inside the web directory. Yii uses this folder to cache the assets. It will have a .gitignore in this folder.

If JavaScript or CSS files are need to be updated, all the folders in this directory need to be deleted. They can be deleted any time and can be auto-generated by Yii as cache files.

commands

This directory allows you to create Yii management scripts to run. These commands can be executed on command line by going on Yii root directory and typing php yii or ./yii. It will display a by default available commands list .

config

The config folder includes configuration settings which include e-mail sending, database connection, etc.

controllers

Controllers manage data traffic in MVC framework. When request is made, it is controller that processes that request.

mail

It stores templates that Yii uses to construct a mail.

models

Models manage all the database work in MVC. Any type of coding related to database is written in model.

runtime

This folder is used during processing of a web requests.

tests

This folder checks the functionality.

vendor

Yii source files reside in this directory. Third party installed module will be stored here. During upgradation, codes in this folder are overwritten hence code alteration in this directory should be avoided.

views

Views in MVC contains the pages which are displayed upon a web request. All the HTML coding is done in view directory.

web

This is the document root directory that the web server points to. The index.php file launches the Yii process when called. In this file, debugging code can be turned on or off. Debug bar is viewable at the bottom of the page.

Here you can put any files, images or anything else which needs web accessibility. Files placed in this folder only will be accessed.

Inside this web directory a subdirectory named asset is also present. This directory is used to respond web requests.





Latest Courses