I am trying to configure DotEnv in a project using CodeIgniter 3.
I see there is a composer.json in the root (outside application folder), so I run:
require vlucas/phpdotenv
I have enabled composer and hooks on config.php:
$config['composer_autoload'] = TRUE;
$config['enable_hooks'] = TRUE;
I have added:
$hook['pre_system'] = function() {
$dotenv = new Dotenv\Dotenv(APPPATH);
$dotenv->load();
};
I have created a .env file inside "application" folder.
My Problem
Vars are not loaded using $_ENV or getenv in database.php
What I have found
I need to run:
composer dump-autoload
If I change composer_autoload from TRUE to:
$config['composer_autoload'] = '[FULLPATH]/vendor/autoload.php';
It works!!
Documentation
According to documentation if we set composer_autoupload to true, it will call the autoload.php from:
application/vendor/autoload.php.
My Questions
- Do this mean, I have to move composer.json to application folder, so vendor is created inside of it?
- is it safe to use $_ENV