PEAR is discontinued

This is a static archive preserving historical releases and metadata. No new packages or updates will be published. For updates to existing packages, or to publish new packages, please use Composer and Packagist.

Home » HTML » HTML_Menu » Bug #6254

Method to get the currently active node

Details

Request #6254Method to get the currently active node
Submitted2005-12-15 22:38 UTC
Fromcweiske at cweiske dot de
StatusWont fix
PackageHTML_Menu
PHP VersionIrrelevant
OSAny
Roadmaps(Not assigned)

Comments

[2005-12-15 22:38 UTC] cweiske at cweiske dot de

Description:
------------
I would ask if you could the following method which returns a reference to the currently active (getCurrentUrl()) node in the $_menu array.
That allows one to change e.g. the title of the active element before rendering the menus, or to get the title of the active element at all.

/**
* Returns reference to the active node element
* (the one where getPath() points to)
*
* @param array $current The array node where the recursion works on currently
* @param array $arPath The value of getPath()
* @param int $nLevel The current recursion level
*
* @return array Reference to the current node array
*/
function &getActive(&$current = null, &$arPath = null, $nLevel = 0)
{
if ($arPath === null) {
$arPath = $this->getPath();
}
if ($current === null) {
$current = &$this->_menu;
}
if ($nLevel < count($arPath)) {
return $this->getActive($current[$arPath[$nLevel]]['sub'], $arPath, $nLevel + 1);
} else {
$strUrl = $this->getCurrentURL();
foreach ($current as $id => $dontuseit) {
if ($current[$id]['url'] == $strUrl) {
return $current[$id];
}
}
$current = null;
return $current;
}
}//function &getActive(&$current = null, &$arPath = null, $nLevel = 0)