Summary
Extended configuration was introduced in ThinkPHP 3.0. The priority of extended configuration is second only to dynamic configuration and higher than conventional configuration, project configuration, etc.
The project configuration file will be included in the compilation cache during deployment mode. That is to say, modifying the project configuration file after compilation will not take effect immediately. You need to delete the compilation cache before it can take effect.
Extended configuration files are not affected by this restriction. Even in deployment mode, modified configurations can take effect in real time. Based on the above characteristics of extended configuration, usually extended configuration is for some special needs, and some configuration information is separated from the project configuration for the purpose of easy maintenance and management.
Define extended configuration
The extended configuration file is located in the project configuration directory (PS: This is more important), such as Conf/user.php. To enable extended configuration, first The LOAD_EXT_CONFIG parameter needs to be defined in the project configuration file:
'LOAD_EXT_CONFIG'=>'user', // 还可以定义多个扩展配置文件 'LOAD_EXT_CONFIG'=>'user,db',
As shown in the above parameter definition, the extended configuration can be one or more configuration files.
Edit the Conf/user.php file and write the configuration parameters:
<?php return array( 'USER_TYPE' => 2, 'USER_AUTH_TYPE' => 1, ); ?>
Then in the operation method, you can read the parameters in the extended configuration through the C method:
C('USER_TYPE')
In the project configuration file, you can also load the extended configuration file in the secondary configuration mode:
'LOAD_EXT_CONFIG'=>array('USER'=>'user','DB'=>'db'),
Then for the same user.php extended configuration file, the way to obtain the configuration parameter value is changed to:
C('USER.USER_TYPE')
The secondary configuration method can avoid parameter conflicts in large projects.
Avoid conflicts with system built-in configuration files
The configuration files listed in the table below have been used by the ThinkPHP system. Do not use them when defining extended configuration files. The following file name:
For more related ThinkPHP knowledge, please visit ThinkPHP Tutorial!
The above is the detailed content of Notes on ThinkPHP extension configuration. For more information, please follow other related articles on the PHP Chinese website!