Jump to content

Settings should have a setter that writes to the DB


Colonel_mortis

Recommended Posts

Posted

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
Posted

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.

Posted
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?

Posted

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();

Posted
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.

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...