CodeIgniter Forums
How do nested variables within the .env file work in CodeIgniter 4 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: How do nested variables within the .env file work in CodeIgniter 4 (/thread-76891.html)



How do nested variables within the .env file work in CodeIgniter 4 - Dozor - 06-30-2020

Under the "Nesting Variables" section in the CI4 documentation under General Topics -> Configuration:

"To save on typing, you can reuse variables that you’ve already specified in the file by wrapping the variable name within ${...}"
example in the documentation:
Code:
BASE_DIR="/var/webroot/project-root"

CACHE_DIR="${BASE_DIR}/cache"

TMP_DIR="${BASE_DIR}/tmp"


I was trying to use the following
Code:
app.baseURL = 'http://localhost:8080/'

google.redirect = ${app.baseURL}Google

However, it's assigning it as a literal when print_r($_ENV)
Code:
[google.redirect] => ${app.baseURL}Google


I've tried using non-namespaced keys including BASE_DIR (per the example) and it keeps printing as a literal.



What's strange - When I use the following:
Code:
CI_ENVIRONMENT = development

google.redirect = ${CI_ENVIRONMENT}Google

The result when print_r is:
Code:
[CI_ENVIRONMENT] => development

[google.redirect] => developmentGoogle


My question is - What am I doing incorrectly and/or how should these be set/used correctly?
According to the documentation, It makes it seem like I should be able to use any key within the .env file that was already assigned using
${somekeyinthisenvfile}



CI version: 4.0.3
PHP 7.4.0

Using CI CLI


RE: How do nested variables within the .env file work in CodeIgniter 4 - Dozor - 06-30-2020

To add onto this:

I've tried the following
Code:
CI_ENVIRONMENT = development
x = test
somerandomvariablename = foo

control = ${CI_ENVIRONMENT}
google.redirect1 = ${x}GoogleLogin
google.redirect2 = ${somerandomvariablename}GoogleLogin
justatestwithnodotinvarname = ${somerandomvariablename}GoogleLogin


Which produces the following in print_r($_ENV):
Code:
[CI_ENVIRONMENT] => development
[x] => test
[somerandomvariablename] => foo

[control] => development
[google.redirect1] => ${x}GoogleLogin
[google.redirect2] => ${somerandomvariablename}GoogleLogin
[justatestwithnodotinvarname] => ${somerandomvariablename}GoogleLogin



RE: How do nested variables within the .env file work in CodeIgniter 4 - Dozor - 06-30-2020

Looks like the DotEnv.php file from composer was outdated.

answer from StackOverflow:
https://stackoverflow.com/questions/62648655/how-do-nested-variables-within-the-env-file-work-in-codeigniter-4