API15

JNode

From Joomla! Documentation

Revision as of 19:59, 24 March 2017 by JoomlaWikiBot (talk | contribs) (preparing for archive only)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

The "API15" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

JNode is a class that allows you to create nodes, normaly used as "leaves" of object-trees. Often used in conjunction with the JTree class.

Defined in[edit]

libraries/joomla/base/tree.php

Methods[edit]

Method name Description
__construct Class constructor, overridden in descendant classes.
addChild
getParent
setParent
hasChildren
getChildren

Importing[edit]

jimport( 'joomla.base.tree' );



Examples[edit]

Code Examples[edit]

Tree Structures with JNode

JTree and JNode can be used to create and process simple tree structures. Let's see how this works for JNode with a simple example.

We want represent the family structure of the Smiths. Granny Barbara has two daughters. Stefanie and Aunti Sue. Stefanie has two children, Peter and Stewie. Auntie Sue doesn't have children.

Let's take a look how we can represent this familiy in an object tree.

$barbara = new JNode();
$stefanie = new JNode();
$sue = new JNode();
$peter = new JNode();
$stewie = new JNode();

//Granny Barbara has two children, stefanie, and sue
$barbara->addChild($stefanie);
$barbara->addChild($sue);

/*
 * Sometimes we want declare parent-child relationships the other way around.
 * We can also do that
 */

$peter->setParent($stefanie);
$stewie->setParent($stefanie);
Batch1211 19:48, 22 March 2010 (EDT) Edit comment