• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do nested variables within the .env file work in CodeIgniter 4

#1
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
Reply

#2
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
Reply

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

answer from StackOverflow:
https://stackoverflow.com/questions/6264...eigniter-4
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.