Configuration method

File configuration

The project root directory configures a name called. env file, configured in KV format, and the data configured for this file can be loaded into memory for business use.

APP_DEBUG = 1
SWOFT_DEBUG = 1

System variables

In addition to file configuration, you can configure some parameters to system variables, and the parameters of system variables are loaded into memory for business use

How to use

Swoft provides a function to read data configured in both ways.

env(string $key = null, mixed $default = null): mixed

Gets the value of an environment variable or all environment variable parameters

  • Returns the value of the environment variable key, and returns the default value if the environment variable key does not exist. If the key parameter is omitted, all environment variables are returned as associative array arrays
  • Default defaults, which can make any type, or it can be a closed package
  • The return value is converted by default. For example true , configure strings, return the conversion to a bool type

Rules

Configuration (String) Convert type Results
true/false/(true)/(false) Bool
empty String (empty string)
null Null
A_B If there is a constant, turn to the corresponding value
/docs/2.x/en/config/env.html
progress-bar