HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
What is the right way to use our custom config file?
Currently, we have a config file which is being used by the application and is being updated whenever any setting gets changes at backend.
I am just wondering, like can we have our config file and so that we do not require to add anything in system default file?
Also in order to use it, do we need to include it in config.php or there is any other way out?
0
Comments
The only writable folders in Vanilla should be /cache, /conf and /uploads. Therefore your applications config file should never be changed by Vanilla (neither by code nor by the dashboard).
Vanilla uses two config files and the best approach is to stick to this behavior. The configuration file in "/applications/[your application]/settings/configuration.php" is there for providing defaults.
Changing any configs either by code or the dashboard should create a key for that setting in the /conf/config.php
If the config settings would be written to your applications config file, they would be overwritten when there is an update of your application. That's another reason why your original config file shouldn't be changed.
Only use the handy shortcuts
c()
andsaveToConfig()
and maybetouchConfig()
. Then there shouldn't be any ways to do something wrong.If you really want to have an external config file, e.g. for holding API keys during development, I would suggest something like that:
But for anything other than development purposes, I do not see a reason to use it like that.
I'd also suggest reading on Gdn::get() and Gdn::set() in https://docs.vanillaforums.com/developer/framework/helpers/
That is a very good hint! Some rarely used config settings should better be saved to the database with the mentioned methods instead of wasting memory in the always loaded config.
I always forget about that when writing plugins...
okay thanks for your inputs.