2

For a Yii 1 web application, I am using the symfony/dotenv library to read and load environment variables from a .env file. To do this, I added a code in the index.php file,

require 'vendor/autoload.php'; //autoload for composer

if(file_exists('/path/to/.env')){
    $dotenv = new Symfony\Component\Dotenv\Dotenv();
    $dotenv->load(__DIR__.'/path/to/.env');
}
else{
   // Missing .env file
   exit;
}

This works well with the web application. However, for Yii console applications, this does not work because index.php is not being loaded. Can this be done inside the console.php file? How?

jackeblagare
  • 407
  • 7
  • 21

1 Answers1

0

For console application you can do the same in protected/yiic.php. This file is used for bootstrap when you call ./yiic, in similar way as index.php is loaded on web request.

rob006
  • 21,383
  • 5
  • 53
  • 74