Invision Community 4: SEO, prepare for v5 and dormant account notifications Matt November 11, 2024Nov 11
Posted December 23, 20159 yr I don't think it's right that my app should have to manually handle unsetting the settings cache and updating the DB for something as simple as changing a setting - it should all be handled by \IPS\Settings::i()->my_setting_name = "a value"; IMO.
December 23, 20159 yr Management Yeah. I do see your point and I've thought this now and again. However, one might temporarily assign a new value to a setting (although this would be a bad habit to get into) and you may not want it being saved.
December 24, 20159 yr Author Yeah. I do see your point and I've thought this now and again. However, one might temporarily assign a new value to a setting (although this would be a bad habit to get into) and you may not want it being saved. Maybe have a function like \IPS\Settings::i()->update("my_setting_name", "a value"); so that it's backwards compatible?
December 25, 20159 yr consider to update on db with a constant (update_db on/off to switch mode when you would) or set param on ::i(true)->....
December 25, 20159 yr Yea, i also missed it as i started using IPS4, but i changed my mind. Most of the time the value comes from a form and then you can use $form->saveAsSettings();
December 25, 20159 yr Author Yea, i also missed it as i started using IPS4, but i changed my mind. Most of the time the value comes from a form and then you can use $form->saveAsSettings(); A lot of the time, that is true, but it's not always the case For example, in the application that I have been working on recently, when you submit the form, some of the fields are saved to settings, and some are saved to a custom DB table. If I use $form->saveAsSettings(); it will save some things to settings that I don't want to put there; some of the fields also need more processing before being saved. I am (now) aware that you can pass custom data into saveAsSettings, but it would be cleaner and more flexible IMO to just call \IPS\Settings::i()->set("key", "value"); or even \IPS\Settings::i()->set(array("key"=>"value", "key2"=>"value2")). Save as settings could then just become a wrapper around that function.
Archived
This topic is now archived and is closed to further replies.