Home > PHP Framework > YII > What does yii application mean?

What does yii application mean?

(*-*)浩
Release: 2019-11-07 14:08:39
Original
2527 people have browsed it

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".

What does yii application mean?

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',
)
Copy after login

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(...);
Copy after login

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);
Copy after login

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
Copy after login

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!

Related labels:
yii
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template