| 5 bootstrap.inc | variable_get($name, $default) |
| 6 bootstrap.inc | variable_get($name, $default) |
| 7 bootstrap.inc | variable_get($name, $default = NULL) |
| 8 bootstrap.inc | variable_get($name, $default = NULL) |
Returns a persistent variable.
Case-sensitivity of the variable_* functions depends on the database collation used. To avoid problems, always use lower case for persistent variable names.
Parameters
$name: The name of the variable to return.
$default: The default value to use if this variable has never been set.
Return value
The value of the variable.
See also
597 functions call variable_get()
File
- includes/
bootstrap.inc, line 974 - Functions that need to be loaded on every Drupal request.
Code
<?php
function variable_get($name, $default = NULL) {
global $conf;
return isset($conf[$name]) ? $conf[$name] : $default;
}
?> Login or register to post comments
Comments
_
If you use variable_get() for a #default_value in a form, it is common practice to use the same variable name as the form element it's associated with.
When you do this when using system_settings_form($form) to return your admin forms, this will automatically save the new values to the variable that is given in variable_get().
<?php
$form['form']['my_form_element'] = array(
'#title' => t('Title'),
'#type' => 'textarea',
'#default_value' => variable_get('my_form_element'),
);
return system_settings_form($form);
?>
An approach for multiple variables in one form can be found here: http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/variab...
Variables per domain
Anyone knows if there's a way to get system variables per domain.. using Domain Access module?
Strongarm
You can get the system varibles with Strongarm http://drupal.org/project/strongarm.