Userdata functions
(→new) |
(→get()) |
||
Line 20: | Line 20: | ||
===get()=== | ===get()=== | ||
− | $ | + | $myplugin->get(); |
[[Category:Plugins]] | [[Category:Plugins]] |
Revision as of 16:40, 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("account_id", $_POST['account_id']); $myplugin->set("username", $_POST['username']); $myplugin->set("password", $_POST['password']);
get()
$myplugin->get();