Categories and CategoryNodes API Guide

From Joomla! Documentation

Revision as of 02:12, 14 October 2019 by Robbiej (talk | contribs) (Initial page creation)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


The Joomla Categories and CategoryNode APIs enable you to access details of Joomla categories. The diagram below illustrates how the Joomla category classes relate to the database structures.

Categories diagram

The Joomla Categories table is split into "partitions", one partition for each component which uses categories. (Here "partitions" is used in a loose sense, not related to the technical term "database partition" for example). Within each partition the category records are held within a tree structure, but always associated with the same component – for example, you can't have a com_content category which has as a parent a com_contact category.

Each component record which is associated with a category holds the id of the category record (as a foreign key), with all the category attributes being held in the category record within the Categories table. (Shown in the diagram using the example of com_contact).

There are 2 Joomla classes (shown in yellow) which provide APIs for accessing category data:

  1. Categories – This relates to the partition within the Categories table. You must first of all specify which partition you want to access by creating a Categories object and passing the name of the component as a parameter to the constructor.
  2. CategoryNode – This relates to an individual Category record. Once you have the Categories object you can get access to the CategoryNode objects within that partition.

In your code you can access the category data for several components, through creating several Categories instances, one for each component/partition.