Home > Backend Development > PHP Tutorial > thinkPHP5.0 framework environment variable configuration method

thinkPHP5.0 framework environment variable configuration method

不言
Release: 2023-03-25 11:50:01
Original
1158 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 detailed content of thinkPHP5.0 framework environment variable configuration method. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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