Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

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?

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    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()and saveToConfig() and maybe touchConfig(). 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:

    public function gdn_pluginManager_afterStart_handler($sender) {
        gdn::config()->load('/where/ever/that/file/is/config-custom.php');
    }
    

    But for anything other than development purposes, I do not see a reason to use it like that.

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    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... :mrgreen:

  • okay thanks for your inputs.

Sign In or Register to comment.