In the .env file there are settings of key values; for example: APP_ENV=prod
How to get the value of the key APP_ENV
for example?
See https://github.com/symfony/dotenv / https://symfony.com/doc/4.1/components/dotenv.html , which parses into $_ENV
, and PHP has a getenv function which you use to get the value out of.
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');
$appEnv = getenv('APP_ENV');
// you can also use ``$_ENV`` or ``$_SERVER``
You can use the Dotenv()
class as the documentation describe here you can call the APP_ENV
like this
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load('..\.env');
$appEnv= $_ENV['APP_ENV'];
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.