Detailed explanation of thinkPHP5.0 framework environment variable configuration example code

黄舟
Release: 2023-03-06 17:20:02
Original
1414 people have browsed it

This article mainly introduces the thinkPHP5.0 framework environment variable configuration method, and analyzes the function, definition, configuration and related environment variables in thinkPHP5.0 in the form of examples. Notes, friends who need it can Refer to the example below

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, with a value of null, no and false are equivalent to "", and 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_PREFIXconstant.

Note,Environment variables do not support arrayparameters. 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

and 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 Detailed explanation of thinkPHP5.0 framework environment variable configuration example code. 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!