4

I'm working on an install profile which brings in various modules and I was curious about the proper (or popular) convention for setting global variables Right now I have two different ways of doing this:

  1. In my settings.php file I set some variables directly in the $conf array:

    $conf['var'] = 'setting';

  2. In the install function of my profile I set some variables using variable_set:

    variable_set('var', 'setting');

I recognize that the first one will permanently retain the setting until the php file is altered, while the other can be changed at any time.

Is there any popular opinion/convention on the method of setting these variables(in the context of using an install profile)?

Thanks!

2 Answers 2

3

In general using hook_install or hook_enable or a hook_update function in a module is prefered over hardcoding the value in settings.php of your drupal site.

Another option is to use the Configuration module or Features to encapsulate your database configuration to code to be enabled on the drupal website.

2

I am using settings.php for settings that are different in otherwise identical sites (staging, dev, production), so that I don't have to change the settings in the database when I sync the sites.

Some modules override database variables with settings in settings.php, like search api override.

Since settings.php is often the only site specific file, it is a handy place for making the rest of the site portable.

For an installation profile, I would set variables using variable_set.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.