Yii Entry Scripts - Yii

What are Yii Entry Scripts?

Yii Entry Scripts are the user accessible PHP scripts which stand responsible to start a request handling cycle.

The structure of an application is illustrated blow:

Entry Script Structure

Web application and also the console application possess only single entry script. The requests are made by the end user to the entry script. The application instances are initiated by the entry script and the requests are forwarded to them.

The entry script of a console application is stored in Yii.php, a project based path and the entry script for the web application is stored in index.php, a web accessible directory.

What does the Yii Entry scripts do?

The entry script

  • Define constants.
  • Register Composer autoloader.
  • Include Yii files.
  • Load configuration.
  • Create and configure an application instance.
  • Process the incoming request.

The entry script for the basic application template is:

The entry script for the console application is:

Global constants are defined best in entry scripts. Yii constants support three entry scripts -

  • YII_DEBUG – Defined whether in debug mode. If set to true, then more log data is seen and detail error call stack.
  • YII_ENV − Defines the environment mode. The values available are prod, dev, and test and the default value is prod. They are used to define in configuration files, for instance, a different DB connection (local and remote) or other values.
  • YII_ENABLE_ERROR_HANDLER − Specifies whether to enable the default Yii error handler.

The code used to define a global constant is:

Note – Global constants are defined at the beginning of entry script so as to take effect when other PHP files are included.

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Yii Topics