This article mainly introduces the environment variable configuration method of thinkPHP5.0 framework, and analyzes the functions, definitions, configurations, and precautions of the environment variables in thinkPHP5.0 in the form of instances, for more information about how to configure environment variables in thinkPHP5.0, see the next article. This article analyzes the functions, definitions, configurations, and precautions of environment variables in thinkPHP5.0 using examples, for more information, see
This document describes how to configure environment variables of the thinkPHP5.0 framework. We will share this with you for your reference. The details are as follows:
Environment variable configuration is allowed, and the priority level is higher than that in the configuration file, because when reading configuration parameters, the system first checks whether the configuration exists in the environment variable.
During development, you can simulate environment variable configuration under the application root directory. the configuration parameter definition format in the. env file adopts the ini method, for example:
app_debug = trueapp_trace = true
If the environment variables are configured separately in your deployment environment, delete the. env configuration file to avoid conflicts.
Parameters configured for environment variables are converted to uppercase values. values of null, no, and false are equivalent to "", and values of yes and true are equivalent to "1 ".
The default environment variable prefix of ThinkPHP5.0 is PHP _. you can also reset it 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 and define the configuration parameter names:
database_username = rootdatabase_password = 123456
Or use
[database]username = rootpassword = 123456
You can use the following two methods:
Config: get ('database. username'); Config: get ('database. password '); // You can also get Config: get ('database _ username'); Config: get ('database _ password') in the following way ');
The above is a detailed description of the sample code of thinkPHP5.0 framework environment variable configuration. For more information, see other related articles in the first PHP community!