Need to know how to add settings to db and pull them out from the Configure menu of Admin tool

bryce alvord Posted in Component Development 9 months ago

I am writing a new component that will integrate a google sheets document with billing balances and match the balance in the sheet to the logged in user. Right now I have just hard coded my Sheets URL with API Key in the code but I want to add this to the configure menu in the admin dashboard in order to make it clean. So really I want to add two things, a text input for the URL and a text input for an error message in case a match couldnt be found between the logged in user and a user in the Sheets document. Could someone point me in the right direction?

Thanks!

Replies
us Bryce alvord Replied 9 months ago

Thanks ~Z~ Man, I really appreciate the help! That was a great explanation. I understand now

German ~Z~ Man Replied 9 months ago

Looks a little bit like that, yes.

There's an example in the how-to, and yesterday I posted another one in https://www.opensource-socialnetwork.org/discussion/view/3173/how-can-i-keep-the-left-side-bar-groups-visible-all-the-time

So what's the problem? You're interested in retrieving/saving component settings, ok. Hence, my next step would be having a look at a component which IS in fact retrieving/saving settings. And since it's always a good idea to use the simplest one, my favorite would be OssnSmilies. Then let's have a look at its settings page now ...


http://z-mans.net/ossn-reports/3180/smilies-1.png


Okay, we see 1 input field, and right clicking into it and choosing 'Inspect' will open the browser's dev console highlighting a select tag named compatibility_mode. Right this already looks like a promising search term, and in fact searching the source for 'compatibility_mode' will return:

  • components/OssnSmilies/plugins/default/forms/OssnSmilies/administrator/setting s.php, that's the form RETRIEVING and displaying the value from the database

and

  • ./components/OssnSmilies/actions/smilies/admin/settings.php, that's the action SAVING the chosen setting back to the database

And having a look into these files already answers your question: getComSettings("COMPONENT") is doing the read, while setSettings("COMPONENT", array of settings) is doing the write.

us Bryce alvord Replied 9 months ago

I understand how to search source code, my question was about how to save and retrieve multiple values from the database. Unless Im misunderstanding something maybe