You are not logged in.
Hello,
I'm developing a plugin to do XYZ. I'd like to use the existing appSettings class to store all my plugin's settings in the db.
What is the proper way to do this? There is no documentation on the API for writing plugins so I'm having to dig through all the hitAppt code to figure it out.
During the plugin's install-run.php, I am doing this:
// get settings manager instance
$settingsObj =& appSettings::getInstance();
$baseSettingsName = 'plugin/myplugin/';
$settings = array('setting1', 'setting2', 'setting3');
foreach($settings as $s)
{
$_setting = $baseSettingsName . $s;
$settingsObj->registerSetting($_setting);
$settingsObj->setSetting($_setting, $_POST[$s]);
}
$settingsObj->save();The above "does" work. I can see in the database that the settings are there. 3 records.
But when I go into run.php and try this:
// get settings manager instance
$settingsObj =& appSettings::getInstance();
$baseSettingsName = 'plugin/myplugin/';
$settings = array('setting1', 'setting2', 'setting3');
foreach($settings as $s)
{
$_setting = $baseSettingsName . $s;
$$s = $settingsObj->getSetting($_setting);
}I get a whole bunch of "Setting 'plugin/myplugin/setting1' is not defined!"
But if I register the settings, then call load() again (effectively requerying and reloading all the settings again into memory), THEN running the getSetting() code, everything loads fine.
I should NOT have to register() then load() in order to get().
Can someone please explain wtf is going on?
Offline
Hello,
I'm sorry for the delayed reply. Thank you very much for such deep investigations. It is required to "register" a setting before it can be used. It is done mostly for 2 reasons:
1. we need to have some way to manage the settings via admin panel, so it is nice to know what to show in the forms
2. when registering a setting, we also supply a default value for it
Offline
That's understandable, HOWEVER, appSettings::getInstance() makes a database call to load all the settings from DB when you initialize it.
Having to then register my specific settings and then call load() again on the appSettings instance requires yet another DB call.
Is there no way to "pre-register" my settings before making that first DB call?
Offline
Hello,
I see the issue. At this moment, probably it is not such a big overhead issue to make just another database call.
Probably in the future I should separate the registration initialize code, then run load() separately.
Offline