search
HomePHP FrameworkThinkPHPNotes on ThinkPHP extension configuration

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

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 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;),

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;)

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools