Welcome Guest, Not a member yet? Register   Sign In
Access of env-vars in Constants.php
#1

(This post was last modified: 06-21-2022, 10:13 AM by groovebird.)

Hi,

i wanted to do something like that in the Config/Constants.php:
PHP Code:
define('IS_LIVE'getenv('CI_ENVIRONMENT') == 'production');
define('IS_DEV'getenv('CI_ENVIRONMENT') == 'development'); 

but i have no access to the env-variables. How could i do that? I want to keep this variables because in my old CI 3 installation i use this constants a lot and migration would be easier.

A second question: Where is the ENVIRONMENT constant defined? I found this term in the documentation. Is this the CI_ENVIRONMENT in the env file?
Reply
#2

If you set CI_ENVIRONMENT by .env file, it is not loaded yet when Config/Constants.php is loaded.

The ENVIRONMENT is defined in CodeIgniter::detectEnvironment().
It is not CI_ENVIRONMENT, but when ENVIRONMENT is not defined, CI_ENVIRONMENT value will be set.
Reply
#3

(This post was last modified: 06-21-2022, 11:38 PM by groovebird.)

Thank you.

Is there an alternative what i can do instead in order to keep these constants? Do i have to create something different and change the constants? (helper, files in Config/Boot Directory). It was nice if you can give me an idea, thanks.
Reply
#4

Move the define() to app/Config/Boot/*.php
Reply
#5

(06-22-2022, 03:16 AM)kenjis Wrote: Move the define() to app/Config/Boot/*.php

Thank you very much. I need to find the right places and implementations for different things :-)
Reply




Theme © iAndrew 2016 - Forum software by © MyBB