Home  >  Article  >  Backend Development  >  Detailed explanation of thinkPHP5.0 framework environment variable configuration example code

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

黄舟
黄舟Original
2017-03-17 09:10:481476browse

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

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

Or use

[database]
username = root
password = 123456

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

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!

Statement:
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