Colonel_mortis Posted December 23, 2015 Posted December 23, 2015 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.
Management Matt Posted December 23, 2015 Management Posted December 23, 2015 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.
Colonel_mortis Posted December 24, 2015 Author Posted December 24, 2015 16 hours ago, Matt said: 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?
BomAle Posted December 25, 2015 Posted December 25, 2015 consider to update on db with a constant (update_db on/off to switch mode when you would) or set param on ::i(true)->....
Daniel F Posted December 25, 2015 Posted December 25, 2015 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();
Colonel_mortis Posted December 25, 2015 Author Posted December 25, 2015 35 minutes ago, Daniel F said: 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.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.