Home  >  Article  >  php教程  >  Yii (yiiframework) framework (4): entry file index.php

Yii (yiiframework) framework (4): entry file index.php

黄舟
黄舟Original
2016-12-27 10:57:261638browse

Yii entry file:

run();
1, $yii=dirname(__FILE__).'/../yii/framework/yii.php'; Contains the boot file of the yii framework yii.php actually loads the yii basic class YiiBase

2, $config=dirname(__FILE__).'/protected/config/main.php'; to define the configuration file used.

3. defined('YII_DEBUG') or define('YII_DEBUG',true); defines whether to turn on "debug mode". The default is turned on. It is recommended to turn it off in production mode.

4. defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3); Defines the level of logging.

Yii provides a flexible and scalable logging function. The recorded logs can be classified by log level and information classification. By using level and category filters, selected information can be further routed to different destinations, such as a file, email, browser window, etc.

The following log routes are available in Yii:
CDbLogRoute: Save information to a database table.
CEmailLogRoute: Send information to the specified Email address.
CFileLogRoute: Saves information to a file in the application's runtime directory.
CWebLogRoute: Display information at the bottom of the current page.
CProfileLogRoute: Display profiling information at the bottom of the page.
At the same time, we can also set the logging function in the application configuration file main.php:

'log'=>array(
	'class'=>'CLogRouter',
	'routes'=>array(
		array(
			'class'=>'CFileLogRoute',
			'levels'=>'error, warning',
		),
		// uncomment the following to show log messages on web pages
		/*
		array(
			'class'=>'CWebLogRoute',
		),
		*/
	),
),

5. Yii::createWebApplication($config)->run(); Create the CWebApplication class , CWebApplication is a front-end controller that manages controllers in MVC and provides core components. Instantiation is performed through the constructor of the parent class CApplication for path alias mapping, pre-initialization, initialization of error and exception handlers, and registration of core framework components (coreMessages, db, message, errorHandler, securityManager, statePersister, urlManager, request, format and session, assetManager, user, themeManager, authManager, clientScript, widgetFactory in CWebApplication), the configuration array of the configuration file, add behaviors (attachBehaviors), initialize the preloaded components (configured in the configuration file), and finally execute init() to preload CHttpRequest object.

Go back to index.php and execute run() in the front-end controller. First execute the onBeginReques event if there is one, then process the request process, like other frameworks, obtain the route and then distribute the route, mapping to the specified controller file through controller and action.

Here we use a picture to understand the workflow of the YII framework:

Yii (yiiframework) framework (4): entry file index.php

The above is the Yii (yiiframework) framework (4): entry file index. PHP content, for more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement:
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