Userdata functions

From Sohowiki
Revision as of 14:17, 18 August 2007 by JvaMy7 (Talk | contribs)
Jump to: navigation, search

barbecue elettrico lg lcd 26 herny barra grande itaipu de fora ba sardegna piantina televisori jvc lcd 26 free 3gp porn video aklan www centro d abruzzo it albergo quebec fara in sabina libri di decorazioni cd beethoven prefettura viterbo giochi consolle telefax segreteria a-style abbigliamento samsung videocamere mini stick calcilutite diesel giacconi delon karena cinta tam automazione srl conqueror 1086 a.d. un fiume di dollari sites xxx canon a 300 bic ruga pesca apnea tv 42 via show ivete zangalo vacanza benessere trentino sintoamplificatori av altec lansing auricolari e cuffie prestito veneto programma copertina cd que pides tu code satellite tps usl feltre cooper, gordon leroy ivan delphi big bolls multifunzione fax canon cavo hard disk golf 1 9 tdi comfortline nuova golosa king africa partido en vivo de los tiburones berluska i t c beltrami forza venite la girandola snc partita mondiale calcio lynyrd skynyrd bigliettini per la prima comunione integratori fibre auto frog sumo jessica pare ixus 50 canon edyta bartosiewicz krawczyk trudno tak francesca neri diffusori 7 1 sabbatucci e vidotto famosas desnudas deportistas c s computer software srl gazzetta sport palmare occasione lg lcd rz-37lz30 lirik lagu melayu emozion iomega hard disk drive s s c n sodimm 256mb ddr 333mhz pc2700 yamaha xt revamped per fare quiz patentino rs-mmc 512 dual voltage 6630 cf card gprs lettori dvd e divx pioneer rikki pure heart disegno sul muro spa zoom 6x la sorella di bruce lee macchine truccate adidas mei hp nx 6110 p-m 740 midnight hour pickett shantung instant portami lontano www disnay televisore 29 100hz lettori dvd vcd jpeg km0 fiat multipla benzina auto km 0 www providian com giovanni marchese to this love la oreja de van zucchero fornaciari zuccherifici syncback pcgratis ozon ochi tai dove rifarsi il seno cavo rca minijack emmanuil, cesare mercedes serie ml roma sito beni culturali bova ultimo cunha, euclydes da- supratutto asrock 939s56-m hamlet dvb transfert portal polti vaporetto eco pro 3000 profumi uomo herrera jewel lyrics spirit victoria gemme snc marron five this love testo bikini micro accademia di danza di montecarlo prince of persia gioco enriko canzone amicizia www cupa it pigiama uomo favola di pinocchio mode sector terratec t2 usb 2 0 dvb-t boblbobl abile rennie, john fiat cinquecento happy hour la pantera rossa www google copm casse acustiche mini export manager (regione lombardia - milano provincia) iomega portable hard disk giro d italia 2001 casio z40 ristoranti caserta hotel ad amsterdam star sailor jeep grand cherokee 2002 pc transfer nec 313 diciotto scandalo blaze tunisia hotel lisola sconosciuta coltello offerte pc alessia merz merz nuda jura 385 langelo del ring spugne di mare da rgb a component notre dame des paris i case ipod test drive off-road 3 ci vediamo marco masini rx v450 cerca lassassino trailer selen mpg free www fitnessring it trama nozze di figaro abbinare colori uguali big angel sigla telefilm buffy festa arma carabiniere lisola che scotta giorgio stefy visitare l abruzzo spinaci nuova espansione per anarchy online ml 2250 toner prostitutas com le avventure di tarzan emanuela nay alfa romeo gtv una donna due passioni ita integrated technology automation suites per violoncello di bach nomadi mediterraneo gommapiuma materassi festivalbar blue 2004 oraziano server news libero siemens s645 gigaset urbis midi sslazio donnald it agriturismo sorrento sexy ebonies orienta giovani christmas sexi baktay, ervin noche de ronda ssteb ==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.

Contents

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 (i.e. preference settings, color values, etc.), stop, follow the vague memory of this sentence back to this page, and check out this userdata method.

When NOT to use it

If your plugin needs to insert multiple records or rows of something --- like coupon codes, guestbook entries, etc. --- you probably still want to create a dedicated table for that. The userdata functions are not meant for that.

Why it's useful

  • Fewer lines of code
  • Fewer keystrokes per line (no mysql query strings to write)
  • No worrying about creating a separate db in the install manifest.
  • Plugin userdata automatically uninstalled by product, no need to account for it in 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 the name of your plugin folder. 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])
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 data from specific field.

echo $myplugin->get("firstname");

Example #2: Get all userdata stored for your plugin in an associative array (indexed by fieldname). Think of this as doing a mysql_fetch_array() on that one-row table you were going to create before discovering this userdata stuff.

$myprefsArray = $myplugin->get();

Bringing it all together

In this example, each available function is used.

$myplugin = new userdata("myplugin");

$myplugin->set("firstname", "John");
$myplugin->set("lastname", "Smith");

// This outputs "John Smith"
echo $myplugin->get("firstname")." ".$myplugin->get("lastname");

// This also outputs "John Smith"
$myData = get();
echo $myData['firstname']." ".$myData['lastname'];

Setting default values

Let's say you're using the userdata functions to store color values that you then retrieve in a template include to colorize certain template elements accordingly. Without setting any default values, the template will likely have a bunch of un-colored parts that should have colors (think transparent backgrounds where a solid bg color is expected) --- which may look a bit screwy --- until the user goes in to your config form and actually sets some values for those colors. This is where defaults come in handy. Here's how you can do them...

Example #1 - Setting a default background color of "#cccccc" (light gray) for an html element that you're outputting with a php template include.

<?
# Gotta do this first before you try to store/retrieve any of your data
# You can think of it like setting the "mode" to "working data related to your plugin specifically"
$mycolors = new userdata('myplugin');

# If no value exists, set the default
if ( $mycolors->get("headerbg") == "" ) {
   $mycolors->set("headerbg", "cccccc");
}
?>

<div id="header" style="background-color: #<? echo $mycolors->get("headerbg"); ?>;">
 This is my header
</div>
Personal tools