CodeIgniter Forums
array in .env file - 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: array in .env file (/thread-71933.html)



array in .env file - obozdag - 10-13-2018

In App.php there is an array variable:
    public $toolbarCollectors = [
        'CodeIgniter\Debug\Toolbar\Collectors\Timers',
        'CodeIgniter\Debug\Toolbar\Collectors\Database',
        'CodeIgniter\Debug\Toolbar\Collectors\Logs',
        'CodeIgniter\Debug\Toolbar\Collectors\Views',
//        'CodeIgniter\Debug\Toolbar\Collectors\Cache',
        'CodeIgniter\Debug\Toolbar\Collectors\Files',
        'CodeIgniter\Debug\Toolbar\Collectors\Routes',
        'CodeIgniter\Debug\Toolbar\Collectors\Events',
    ];

Is it possible to define an array variable in .env file?
For example:
app.css_files = [
     'bootstrap.css',
     'fontawesome.css',
     'stylesheet.css'
]
or
app.css_files = ['bootstrap.css', 'fontawesome.css', 'stylesheet.css']


RE: array in .env file - sv3tli0 - 10-13-2018

This array doesn't sounds as environment thing, probably it's place is not in the .env

.env should be used to put only specific configuration settings which are critical for running the environment not everything..
In some cases you can even not use the .env and to set such settings directly at config files if it is will be same for all env's.


How ever at the moment I see maybe only option to set json array string as setting (in single line) at .env and to parse it where you use it.

app.css_files = '["bootstrap.css","fontawesome.css","stylesheet.css"]'


RE: array in .env file - obozdag - 10-14-2018

app.css_files = '["bootstrap.css","fontawesome.css","stylesheet.css"]' is returning a string. In .env file there is an example but I think it doesn't work either. If so, CodeIgniter4 .env file style may be changed from apache to json or something else.
# app.CSRFExcludeURIs = []


RE: array in .env file - ciadmin - 10-14-2018

Er, don't we already have what you are asking for?
https://bcit-ci.github.io/CodeIgniter4/general/configuration.html#treating-environment-variables-as-arrays


RE: array in .env file - sv3tli0 - 10-15-2018

(10-14-2018, 09:14 PM)obozdag Wrote: app.css_files = '["bootstrap.css","fontawesome.css","stylesheet.css"]' is returning a string. In .env file there is an example but I think it doesn't work either. If so, CodeIgniter4 .env file style may be changed from apache to json or something else.
# app.CSRFExcludeURIs = []

Yes, you need just to json_decode($IT, true) to get normal array. I think this is more then enough for such type of LIST.


(10-14-2018, 10:39 PM)ciadmin Wrote: Er, don't we already have what you are asking for?
https://bcit-ci.github.io/CodeIgniter4/general/configuration.html#treating-environment-variables-as-arrays

Yes but those are assoc arrays. He is asking for just a list of entries without keys..

Code:
SimpleConfig.address.city = "Berlin"
SimpleConfig.address.country = "Germany"
vs
Code:
SimpleConfig.address.0 = "Berlin"
SimpleConfig.address.1 = "Munich"