Home > Backend Development > PHP Tutorial > About the configuration method of environment variables in thinkPHP5.0 framework

About the configuration method of environment variables in thinkPHP5.0 framework

不言
Release: 2023-03-31 09:24:02
Original
1801 people have browsed it

This article mainly introduces the thinkPHP5.0 framework environment variable configuration method, and analyzes the function, definition, configuration and related precautions of environment variables in thinkPHP5.0 in the form of examples. Friends in need can refer to it

The example in this article describes the thinkPHP5.0 framework environment variable configuration method. Share it with everyone for your reference, the details are as follows:

Allows the use of environment variable configuration, and the priority level is higher than in the configuration file, because when reading the configuration parameters, it will first determine whether the environment variable exists This configuration.

During the development process, you can simulate environment variable configuration in .env under the application root directory. The configuration parameter definition format in the .env file adopts the ini method , for example:

app_debug = true
app_trace = true
Copy after login

If your deployment environment has separately configured environment variables, please delete the .env configuration file to avoid conflicts.

Environment variable configuration parameters will all be converted to uppercase, the value is null, no and false are equivalent to "", and the value of yes and true are equivalent to "1".

The default environment variable prefix of ThinkPHP5.0 is PHP_, which can also be reset by changing the ENV_PREFIX constant .

Note,Environment variables do not support array parameters. If you need to use array parameters, you can use underscores to separate the configuration parameter names:

database_username = root
database_password = 123456
Copy after login

Or use

[database]
username = root
password = 123456
Copy after login

Then you can use the following two methods to obtain:

Config::get('database.username');
Config::get('database.password');
// 同时下面的方式也可以获取
Config::get('database_username');
Config::get('database_password');
Copy after login

The above is the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

Analysis of Yaf route rewriting in the PHP framework

About independence in the thinkPHP5.0 framework Methods of configuration and dynamic configuration

The above is the detailed content of About the configuration method of environment variables in thinkPHP5.0 framework. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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