A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.yiiframework.com/doc/guide/2.0/en/structure-entry-scripts below:

Application Structure: Entry Scripts | The Definitive Guide to Yii 2.0

Entry Scripts

Entry scripts are the first step in the application bootstrapping process. An application (either Web application or console application) has a single entry script. End users make requests to entry scripts which instantiate application instances and forward the requests to them.

Entry scripts for Web applications must be stored under Web accessible directories so that they can be accessed by end users. They are often named as index.php, but can also use any other names, provided Web servers can locate them.

Entry scripts for console applications are usually stored under the base path of applications and are named as yii (with the .php suffix). They should be made executable so that users can run console applications through the command ./yii <route> [arguments] [options].

Entry scripts mainly do the following work:

Web Applications

The following is the code in the entry script for the Basic Web Project Template.

<?php

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();
Console Applications

Similarly, the following is the code for the entry script of a console application:


<?php


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/console.php';

$application = new yii\console\Application($config);
$exitCode = $application->run();
exit($exitCode);
Defining Constants

Entry scripts are the best place for defining global constants. Yii supports the following three constants:

When defining a constant, we often use the code like the following:

defined('YII_DEBUG') or define('YII_DEBUG', true);

which is equivalent to the following code:

if (!defined('YII_DEBUG')) {
    define('YII_DEBUG', true);
}

Clearly the former is more succinct and easier to understand.

Constant definitions should be done at the very beginning of an entry script so that they can take effect when other PHP files are being included.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4