Back to Categories class

Method get

public \Joomla\CMS\Categories\CategoryNode|null
get
(mixed $id = 'root', mixed $forceload = false)
Loads a specific category and all its children in a CategoryNode object.
Parameters
  • mixed $id an optional id integer or equal to 'root'
  • bool $forceload True to force the _load method to execute
Returns
  • \Joomla\CMS\Categories\CategoryNode|null CategoryNode object or null if $id is not valid
Since
  • 1.6
Class: Categories
Project: Joomla

Method get - Source code

/**
 * Loads a specific category and all its children in a CategoryNode object.
 *
 * @param   mixed    $id         an optional id integer or equal to 'root'
 * @param   boolean  $forceload  True to force  the _load method to execute
 *
 * @return  CategoryNode|null  CategoryNode object or null if $id is not valid
 *
 * @since   1.6
 */
public function get($id = 'root', $forceload = false)
{
    if ($id !== 'root') {
        $id = (int) $id;
        if ($id == 0) {
            $id = 'root';
        }
    }
    // If this $id has not been processed yet, execute the _load method
    if (!isset($this->_nodes[$id]) && !isset($this->_checkedCategories[$id]) || $forceload) {
        $this->_load($id);
    }
    // If we already have a value in _nodes for this $id, then use it.
    if (isset($this->_nodes[$id])) {
        return $this->_nodes[$id];
    }
    return null;
}