Welcome Guest, Not a member yet? Register   Sign In
Array in .env file
#1

I was hoping from the docs here: Treating Environment Variables as Arrays that I could access something in the .env file that used dot syntax as an array but it doesn't seem to work.[url=https://codeigniter4.github.io/userguide/general/configuration.html#treating-environment-variables-as-arrays][/url]
Here is an example, after copying the env file to .env and uncommenting the database.default section:

PHP Code:
$database getenv('database');
var_dump($database); 

$database just contains boolean false.

Is it possible to access everything prefixed with e.g. 'database' as an array?
Thanks.
Reply
#2

It will not work because it does not have a namespace or class.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#3

thanks but actually I think my fault was using the getenv command.

The following works:

PHP Code:
$database config('Database');
var_dump($database); 

and shows that database.default is an array
Reply




Theme © iAndrew 2016 - Forum software by © MyBB