Home >PHP Framework >YII >What does yii application mean?
Application refers to executing the user's access instructions. Its main task is to parse user instructions and assign them to the corresponding controller for further processing. The application is also a place to store parameters. For this reason, applications are often called "front controllers".
The entry script creates the application as a singleton. The application singleton can be accessed from anywhere through Yii::app().
Application configuration (Recommended learning: yii tutorial)
By default, the application is an instance of the CWebApplication class. To configure it Customization usually provides a configuration file (or array) to initialize its property values when the application instance is created. Another way to customize the application is to extend the CWebApplication class.
Configuration is an array of key-value pairs . Each key name corresponds to an attribute of the application instance, and the corresponding value is the initial value of the attribute. For example, the following code sets the name of the application and the default controller attribute.
array( 'name'=>'Yii Framework', 'defaultController'=>'site', )
We generally Save the configuration in a separate PHP code (e.g. protected/config/main.php). In this code, we return the following parameter array,
return array(...);
To execute these configurations, we generally use this file as A configuration passed to the application's constructor. Or pass it to Yii::createWebApplication() like the following example. We usually define these configurations in the entry script:
$app=Yii::createWebApplication($configFile);
Tip: If the application configuration is very complex, we can divide it into several files, each The file returns a portion of the configuration parameters. Next, we use PHP include() in the main configuration file to merge other configuration files into a configuration array.
The application's home directory
The application's home directory refers to the root directory that contains all PHP code and data with a relatively high security factor. By default, this directory is generally a directory in the directory where the entry code is located: protected . This path can be changed by setting basePath in the application configuration.
Ordinary users should not be able to access the contents of the application folder. In the Apache HTTP server, we can put a .htaccess file in this folder. The content of the .htaccess file is as follows:
deny from all
The life cycle of the application
When processing a user request, an application will go through the following life cycle:
Establish class autoloader and error handling;
Register core application components;
Read Get the application configuration;
Use CApplication::init() to initialize the application.
Read static application components;
Trigger the onBeginRequest event;
Process user requests:
Parse user requests;
Create controls Controller;
Execution controller;
Trigger onEndRequest event;
The above is the detailed content of What does yii application mean?. For more information, please follow other related articles on the PHP Chinese website!