Home > PHP Framework > ThinkPHP > Notes on ThinkPHP extension configuration

Notes on ThinkPHP extension configuration

藏色散人
Release: 2020-02-02 18:45:27
forward
2385 people have browsed it

Notes on ThinkPHP extension configuration

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

<?php
return array(
    &#39;USER_TYPE&#39;          => 2,
    &#39;USER_AUTH_TYPE&#39;     => 1,
);
?>
Copy after login

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

C(&#39;USER_TYPE&#39;)
Copy after login

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

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

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

C(&#39;USER.USER_TYPE&#39;)
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:

Notes on ThinkPHP extension configuration

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!

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 admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template