问题
I am using phpdotenv with Codeigniter. Codeigniter's environment setup doesn't quite work for this project.
I'm trying to set this in my config.php file:
$config['site_id'] = getenv('APP_ID');
phpdotenv is being loaded via the pre_system hook and getenv('APP_ID') is available throughout the app. I've also checked in the core and this fires well before loading config items.
$hook['pre_system'] = function() {
$dotenv = new Dotenv\Dotenv(APPPATH);
$dotenv->load();
};
The value of $this-config->item('site_id')
is always NULL
Any advice as to why this is happening would be really appreciated.
Thanks in advance.
回答1:
Oh, you would basically just do this :
require APPPATH . 'vendor/autoload.php';
$dotenv = new Dotenv\Dotenv(BASEPATH . '../');
$dotenv->load();
来源:https://stackoverflow.com/questions/41088509/why-is-my-config-item-not-populating-from-my-getenv-entry-in-codeigniter