Home  >  Article  >  PHP Framework  >  ThinkPHP extension configuration

ThinkPHP extension configuration

尚
forward
2020-04-08 09:19:422908browse

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',

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(
    &#39;USER_TYPE&#39;          => 2,
    &#39;USER_AUTH_TYPE&#39;     => 1,
);
?>

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

C(&#39;USER_TYPE&#39;)

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

&#39;LOAD_EXT_CONFIG&#39;=>array(&#39;USER&#39;=>&#39;user&#39;,&#39;DB&#39;=>&#39;db&#39;),

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

C(&#39;USER.USER_TYPE&#39;)

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!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete