Home > PHP Framework > ThinkPHP > body text

ThinkPHP extension configuration

Release: 2020-04-08 09:19:42
forward
2673 people have browsed it

ThinkPHP extension configuration

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 features of extended configuration, usually extended configuration is for some special needs, and some configuration information is separated from the project configuration. This purpose is to facilitate 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',
Copy after login

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:

 2,
    'USER_AUTH_TYPE'     => 1,
);
?>
Copy after login

Then in the operation method, you can read the parameters in the extended configuration through the C method:

C('USER_TYPE')
Copy after login

In In the project configuration file, you can also load the extended configuration file in secondary configuration mode:

'LOAD_EXT_CONFIG'=>array('USER'=>'user','DB'=>'db'),
Copy after login

Then for the same user.php extended configuration file, the way to obtain the configuration parameter values ​​is changed to:

C('USER.USER_TYPE')
Copy after login

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:

ThinkPHP extension configuration

Recommended tutorial: thinkphp tutorial

The above is the detailed content of ThinkPHP extension configuration. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
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 [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!