Latest JAS v1.1.0
144 plugins online

Core / Data / Get / Item

Getting an item will try to find the item by it's identifier (typically called "nr") and gather all it's data. This will ignore any of the other filters that may be set (see "All" section below).

To print out the name of the category with identifier #1 try the following:
Get a category item
PHP
$d=Data::cache("categories", "view", "item");    //initialize categories module for item viewing
$d->setValue("nr", 1);    //set the item identifier

if(!$d->get())    //get data
  print $d->e->show();    //show errors in case anything failed
else if($d->next())    //set the value to v array
  print $d->v["name"];    //print out the category name

You can also print out the name of the category with an identifier set in the URL. Imagine the following URL is provided: https://example.com?nr=42 you can use following code to print the name of category #42:
Get a category item dynamically
PHP
$d=Data::cache("categories", "view", "item");
//don't enforce a "nr" value

if(!$d->get()&&$d->next())
  print $d->v["name"];

And don't you worry about validating whether "nr" is actually a valid value (e.g. not "; DELETE * FROM users; ), JAS handles this for you. Anyway you could even go a step further by using the module provided in the URL (https://example.com?m=notes&nr=42):
Get any item dynamically
PHP
$d=Data::cache(false, "view", "item");    //don't enforce module

if(!$d->get()&&$d->next())
  print $d->v["name"];

So what if you want to gather multiple items by their identifier? Well simply supply a multiple values, each with an new "entry" number.
Get multiple category items
PHP
$d=Data::cache("categories", "view", "item");
$d->setValue("nr", 1, 0);    //set the first item identifier
$d->setValue("nr", 42, 1);    //set the second item identifier
$d->setValue("nr", 1337, 2);    //set the third item identifier

//or don't setValue but use an URL like (https://example.com?nr[]=1&nr[]=42&nr[]=1337):

if($d->get())
  while($d->next())    //set the values to v array
    print $d->v["name"];    //print out the category names

So the trick here is that you specified (either implicit or explicit) the value for the field "nr". In case you supply multiple entries it will effectively treat this as separate rows which are set to the "v" array when you loop through them with while($d->next()). To give an idea of how this works in the background the following SQL is generated on the back of the latter example:
(Simplified) Select query
SQL
SELECT *
FROM categories
WHERE nr=1 OR nr=42 OR nr=1337

Comments (0)