Access of env-vars in Constants.php |
Hi,
i wanted to do something like that in the Config/Constants.php: PHP Code: define('IS_LIVE', getenv('CI_ENVIRONMENT') == 'production'); 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?
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.
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.
Move the define() to app/Config/Boot/*.php
I was having the same issue and I still can't get this to work.
App/Config/Boot/development.php Code: defined('ENVI') || define('ENVI', 'development'); App/Config/Boot/production.php Code: defined('ENVI') || define('ENVI', 'production'); App/Config/Constants.php Code: getenv('ENVI') Doesn't have any value. It doesn't blow up with an error either. Code: ENVI Blows up with an error Code: $_ENV['ENVI'] Blows up with an error
@sevmusic I copied your code on a fresh install of CodeIgniter and added dd(ENVI); to the default Home Controller and it showed the appropriate value. You've done something else that isn't working correctly.
|
Welcome Guest, Not a member yet? Register Sign In |