Adding global variables via env.php file #3015
Replies: 2 comments
-
@robinsowell I think this is fine for the time being, and we should document it (hoping you could volunteer to do that). We could do something better in the future, but if it's something that already works, we should have it documented |
Beta Was this translation helpful? Give feedback.
-
@robinsowell I have opened a PR with some changes, perhaps you could get a chance to test it: #3954 There is also documentation PR: ExpressionEngine/ExpressionEngine-User-Guide#781 The main problem with your initial approach is the different priorities - index.php values should have higher priority and override those set in config.php; but if you use $assign_to_config in config file, it's working the opposite. So the PR is allowing you to set global variables directly in config file (which could be plain text or env variables) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
When you're working in multiple environments, it's especially nice to be able to set some global variables in your env.php file.
Say you want a different banner on your local/dev/live sites, or a few globals you can use in coditionals based on whether it's live or dev.
Typically, you can add globals manually via the index.php files and the global array, but env is much more convienient if you're doing multiple environments.
This DOES work:
The one negative, it overrides the global if it's set in the index.php, which it really shouldn't. BUT it does allow you to set globals in the index.php. Just if the same exact one is set in both, config.php overrides it.
We either should make this 'official' and add it to the docs or decide on a different way we'd want it to work. I actually think this is fine, but didn't want to put it in docs without some discussion. And docs would need to note that using this method, you'd override any that conflict with index.php.
Beta Was this translation helpful? Give feedback.
All reactions