Structure of the default web application

The basic application is composed of a SiteController with a couple of modules and a login system.

The configuration files should be quite straightforward to understand and can be found in the /config directory. We will be touching on them every now and then in order to configure certain aspects and extensions we're going to use.

Regardless of whether you are using the manually installed basic application or the Composer-driven method explained earlier, you will be required to set up the database on your environment and configure the application.

In the configuration file web.php, be sure to have set up the cookieValidationKey, and while in db.php, set up the DSN of your database as described in the documentation at http://www.yiiframework.com/doc-2.0/guide-start-databases.html#configuring-a-db-connection.

You will also note the following at the end of the web.php file:

// config/web.php

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = 'yiidebugModule';

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = 'yiigiiModule';
}

By default, Yii 2 will provide you with a YII_DEBUG global constant definition, and an environment YII_ENV_<ENVIRONMENT> definition, which could come handy in certain conditions. Be aware that its use should be limited to specific cases where an alternative and more portable solution cannot be found, either by revisiting the implementation or the initial requirements. In a production environment, YII_DEBUG should be set to false and YII_ENV to prod.

Documentation and sample code

With this version, Yii is now following more strict standards in the way that the code is written and distributed.

Documentation and readability of the code is essential and is mainly dictated by the PSR-1 and PSR-2 coding style guide (note that PSR-2 is explicitly depending on PSR-1), published by PHP-FIG (http://www.php-fig.org).

In PHPStorm, it is quite easy to set up the code style. Alternatively, you can use PHP_Codesniffer (https://github.com/squizlabs/PHP_CodeSniffer) to accomplish the same task and validate your code:

Feel free to browse the code and check what it does. It's not massively different to what Yii 1 sample application did, apart from the use of PHP 5.4 syntactic sugar.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset