Latest JAS v1.1.0
144 plugins online

Core / Data / Get / Tree

Trees can be quite a handy data structure in some cases. The categories module uses this to allow you to organize your data. But how do you get the data from such a "self-referenced" module in a tree form?

Let's build a full tree of all categories:
Get the tree downwards
PHP
$d=Data::cache("categories", "tree", "down");
$d->setValue("catnr", 0);    //set category reference the top level

if($d->get())
  while($d->next())
    print str_repeat("  ", $d->v["treedepth"]." -".$d->v["name"];    //print out the names of all categories, indented based on it's depth in the tree

So what about a crumb-trail?
Get the tree upwards
PHP
$d=Data::cache("categories", "tree", "up");
$d->setValue("catnr", 123);    //set category reference start level

if($d->get())
  while($d->next())
    print $d->v["name"]." / ";    //print out the names of all categories "above" (and include) #123

Comments (0)