Training

Our next U.S. stop:

Mike Anello and Andrew Riley from Mediacurrent are teaming up to offer the first Blue Collar Git workshop on Friday, June 8 as part of DrupalCamp Charlotte (also part of the Southeast LinuxFest). The cost is only $149 for the full day if you register during the month of May ($199 otherwise). 

New Podcast

Posted Wednesday, May 9 at 7:50 am
Brandon Morrison (Brandonian on drupal.org) joins Andrew Riley and Mike Anello on the first post-DrupalCon Denver edition of the podcast to talk about all things Geo in Drupal 7. Brandon is one of the maintainers of the GeoField module and is an active member of the Drupal Geo community.
Download Podcast 82
DrupalEasy_ep82_20120509.mp3
Syndicate content

Newsletter

Stay up-to-date on DrupalEasy workshops and other events. On average, we send about one newsletter per month.

Testimonial

Mike is a great teacher!

Who are we?

DrupalEasy is the collective expertise of Ryan Price and Michael Anello, who joined forces to provide training and consulting services worldwide. Read all about them and what they can do.

What is Drupal?

Drupal is a free, super-powerful content management system for sites that require information posting and collection, including blogs, forums, videos, photos, and databases of information. We think it is the best platform available. Here's why...

Why Drupal?

More and more savvy organizations are going with Drupal for content management, and its no mystery why. It’s free, flexible, and easy to maintain for small or large volume sites. Learn more...

Module Development: Settings Variables in settings.php Using $conf

Sometimes you need to set some global variables in Drupal that aren't used by just a single module, but rather a set of modules. You can take advantage of the $conf array in your site's settings.php file to set these variables that your various modules can then access them using the "variable_get()" method.

For example, I have a client that pulls in some data from an external SQL Server database to their Drupal site. Data is pulled in by a variety of custom modules and they wanted to have a single, secure place to set the database connection information.

If you check out your site's settings.php file, you'll see that it has a "Variable overrides" section:

/**
* Variable overrides:
*
* To override specific entries in the 'variable' table for this site,
* set them here. You usually don't need to use this feature. This is
* useful in a configuration file for a vhost or directory, rather than
* the default settings.php. Any configuration setting from the 'variable'
* table can be given a new value. Note that any values you provide in
* these variable overrides will not be modifiable from the Drupal
* administration interface.
*
* Remove the leading hash signs to enable.
*/

In my case, I went ahead and set the SQL Server database connection information here as follows:

$conf = array(
'sqlserver_dsn' => 'client_dsn',
'sqlserver_username' => 'admin',
'sqlserver_password' => 'super_secret_so_you_better_not_tell_anybody',
);

Then, in the various custom modules, I can easily access the values using:

$dsn = variable_get('sqlserver_dsn', '');

The advantage to my client is that all the DB login information is in a single, secure place.

One warning: the devel module's Variable Editor indicates that it will display all variables including those from the $conf array. This is not the case - it is still a "TO DO" item in the latest -dev version (2009-Apr-23).

You can set lots more in the $conf array. See this related DrupalEasy Quicktip.

Trackback URL for this post:

http://drupaleasy.com/trackback/128
No votes yet

More Quicktips


1 comment

Pingback

[...] You can set lots more in this file. See this related DrupalEasy quicktip for more info. [...]

Syndicate content