Joomla! provides us with the class JRegistry
; this class enables us to store and retrieve data using namespaces. Data stored in a JRegistry
object is organized using a hierarchy based on namespaces.
Namespaces are unique hierarchical tree identifiers used to categorize data. Imagine we want to store the number of sightings of animals in an area. We could use the following hierarchy:
animal animal.total animal.bird animal.bird.chaffinch animal.bird.swan animal.mammal animal.mammal.badger animal.mammal.squirrel.red animal.mammal.squirrel.grey
Based on this example, if we wanted to know how many badgers we have sighted, we would retrieve the value using the registry path animal.mammal.badger
. If we wanted to know how many mammals we have sighted, we would retrieve the value using the registry path animal.mammal
.
Note
A drawback of using this type of hierarchy is that data items can only be stored in one path. This can be difficult if the location of a data item is ambiguous.
The...