Userdata functions

From Sohowiki
(Difference between revisions)
Jump to: navigation, search
(set($fieldname, $data))
(set(fieldname, data))
Line 11: Line 11:
 
  $myplugin = new userdata("myplugin");
 
  $myplugin = new userdata("myplugin");
  
===set(fieldname, data)===
+
===set()===
 
Updates value of specific field (or inserts as new rec if fieldname not found)
 
Updates value of specific field (or inserts as new rec if fieldname not found)
 
<pre>
 
<pre>

Revision as of 16:42, 9 August 2006

Contents

Introduction

The idea behind the userdata class is to make it easy for plugin developers to store and retrieve basic user-inputted information for use with their plugin --- account ids, display preferences, etc. --- without having to create a whole db table for it.

When to use it

If you're developing a plugin and find yourself about to create a whole db table just to store one row's worth of misc information related to your plugin, stop, follow the vague memory of this sentence back to this page, and check out this userdata method. Less lines of code, fewer keystrokes, no worrying about creating and installing the db in the install manifest.

How to use it

new

The basic idea here is to stick this line at the top of any script that uses the get() and set() functions. Replace "myplugin" with your plugin's name. The other methods depend on this being set. If you don't do this first and try to call get() or set() php will bomb a fatal error.

$myplugin = new userdata("myplugin");

set()

Updates value of specific field (or inserts as new rec if fieldname not found)

$myplugin->set("firstname", "mike");

get()

$myplugin->get();
Personal tools