Userdata functions

From Sohowiki
(Difference between revisions)
Jump to: navigation, search
(get())
(get())
Line 29: Line 29:
  
 
'''Example #2:''' Get data from specific field.
 
'''Example #2:''' Get data from specific field.
  $myplugin->get();
+
  $myplugin->get("firstname");
  
 
[[Category:Plugins]]
 
[[Category:Plugins]]

Revision as of 16:49, 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()

Syntax
$myplugin->get([fieldname])
What happens
If $fieldname is NOT passed - Gets all userdata related to passed plugin and returns it in an array
If $fieldname IS passed - Gets data for requested field and returns it

Example #1: Get all userdata stored for your plugin. Think of this as doing a mysql_fetch_array() on that one-row table you were going to create before discovering this userdata stuff.

$myplugin->get();

Example #2: Get data from specific field.

$myplugin->get("firstname");
Personal tools