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

ThinkPHP5.2: Changes in configuration classes

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼forward
2019-12-16 14:48:242243browse

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

The batch (merge) setting usage is retained

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

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

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:
This article is reproduced at:thinkphp.cn. If there is any infringement, please contact admin@php.cn delete