Welcome Guest, Not a member yet? Register   Sign In
How to add variables from a second custom env file to the default one
#1

(This post was last modified: 06-14-2024, 04:13 AM by serialkiller.)

I would need to load an additional env file in addition to the default env file.

It is possible to load an env file with dedicated values and merge them with the default env file values, e.g. .env.myenv?

Latest version of Codeigniter 4.5.2
Reply
#2

I think it's impossible.
 You can read the file .env.local.php in app/Common.php with require "../.env.local.php"
In the file .env.local.php use the setenv() or other functions.
I hope this helps.
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply
#3

In public/index.php, afetr
PHP Code:
$paths = new Config\Paths(); 

use CodeIgniter\Config\DotEnv;

PHP Code:
require_once $paths->systemDirectory '/Config/DotEnv.php';
(new 
DotEnv($paths->appDirectory '/../''.env.' $_SERVER['HTTP_HOST']))->load(); 


But I'm still not sure it's the best way
Reply




Theme © iAndrew 2016 - Forum software by © MyBB