Technical Solution
[CiviCRM] How to add and use your variable in Settings field in CiviCRM database?
I need to store some configuration information about my extension in database. Initially I thought of having a new table to store those. Then I found out that CiviCRM gives that feature. Here is its tip:
- Create a settings folder in your extension folder.
- Create [extension filename].settings.php file
- In that file return an array as in the following example.
return array(
'widget_cache_timeout' => array(
'group_name' => 'Wci Preference',
'group' => 'wci',
'name' => 'widget_cache_timeout',
'type' => 'Integer',
'default' => 0,
'description' => 'Widget timeout',
'help_text' => 'widget timeout',
),
);
Then in the code where you want to save data call following code:
civicrm_api3('setting', 'create', array('sequential' => 1, 'widget_cache_timeout' => $values['widget_cache_timeout']));
For reading the data call following code:
$cacheTime = civicrm_api3('setting', 'getValue', array('group' => 'Wci Preference', 'name' => 'widget_cache_timeout'));
For more information please visit: http://wiki.civicrm.org/confluence/display/CRMDOC/Settings+Reference