Yii2's application structure is very clear, precise, and redundant (for advanced applications).
The contents of the basic
folder should be as follows:
Open web/index.php
to view content:
<?php // comment out the following two lines when deployed to production defined('YII_DEBUG') or define('YII_DEBUG', true); defined('YII_ENV') or define('YII_ENV', 'dev'); require(__DIR__ . '/../vendor/autoload.php'); require(__DIR__ . '/../vendor/yiisoft/yii2/Yii.php'); $config = require(__DIR__ . '/../config/web.php'); (new yii\web\Application($config))->run();
Here, the first two constant definitions are very important.
YII_DEBUG
defines whether you are in debug mode or not. If we set this, we will have more log information and will see the detail error call stack.
YII_ENV
defines the environment mode we are working in, and its default value is prod
. The available values are test
, dev
, and prod
. These values are used in configuration files to define, for example, a different DB connection (local database different from remote database) or other values, always in configuration files.
Since we are at the start of our project, it is recommended to set YII_DEBUG
to true
, in order to have more detailed information in case we make a mistake in our code, instead of the unhelpful, blank.
The following table contains a list of all Yii2's objects: