Home PHP Framework ThinkPHP ThinkPHP5.2: Changes in configuration classes

ThinkPHP5.2: Changes in configuration classes

Dec 16, 2019 pm 02:48 PM
thinkphp5.2

ThinkPHP5.2: Changes in configuration classes

This article summarizes the adjustments in configuration class design in the latest version 5.2.

Cancel convention configuration

The convention configuration file (convention.php) has been officially canceled in the latest version. Before that, it had been moved from the core package to the application warehouse ( root directory). Since the default configurations have all been used as the default attribute configurations of related class libraries, the conventional configuration files are no longer needed.

From the perspective of convenient project configuration, the default configuration is provided under the config directory of the application warehouse, which makes modifications clearer and the configuration can be modified directly.

Cancel dynamic settings

It is recommended that the configuration class be only used for reading and not for dynamic settings, so as to facilitate the unified use of the configuration center management in the future. If third-party configuration extensions (such as Yaconf) are used, setting configuration is not supported. Therefore, the configuration class no longer provides a method for dynamically setting a certain configuration parameter, but due to the needs of some database configurations, the usage of a certain configuration file in batches is retained.

The following usage is no longer supported

Config::set('app.app_name', 'think');
Copy after login

The batch (merge) setting usage is retained

Config::set([
    'app_name' => 'think',
    'default_timezone' => 'Asia/Shanghai',
], 'app');
Copy after login

Unified configuration read operation

The previous pull method for reading first-level configuration has been cancelled. The new version uses the get method to read all configuration values, and the system will automatically judge.

At the same time, the default prefix of the configuration parameters (first-level configuration) is cancelled. All configuration parameters without a dot are considered to read the first-level configuration.

// 读取app配置
Config::get('app');
// 读取具体配置必须改为
Config::get('app.app_name');
// 不再支持原来的读取
Config::get('app_name');
Copy after login

The Config class no longer supports array reading

The Config class no longer uses the ArrayAccess interface, so it no longer supports array reading.

Routing and URL configuration are independent

The configuration parameters related to routing and URL requests are independently configured into the route.php configuration file instead of the app.php configuration file.

PHP Chinese website has a large number of free ThinkPHP introductory tutorials, everyone is welcome to learn.

This article is reproduced from: https://blog.thinkphp.cn/962855

The above is the detailed content of ThinkPHP5.2: Changes in configuration classes. For more information, please follow other related articles on the PHP Chinese website!

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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)