Why is my config item not populating from my getenv() entry in codeigniter?

China☆狼群 提交于 2019-12-24 00:26:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!