Index: library/Zend/Navigation/Page.php =================================================================== --- library/Zend/Navigation/Page.php (revision 24362) +++ library/Zend/Navigation/Page.php (working copy) @@ -40,6 +40,20 @@ * @var string|null */ protected $_label; + + /** + * Fragment identifier (anchor identifier) + * + * The fragment identifier (anchor identifier) pointing to an anchor within + * a resource that is subordinate to another, primary resource. + * The fragment identifier introduced by a hash mark "#". + * Example: http://www.example.org/foo.html#bar ("bar" is the fragment identifier) + * + * @link http://www.w3.org/TR/html401/intro/intro.html#fragment-uri + * + * @var string|null + */ + protected $_fragmentIdentifier; /** * Page id @@ -328,6 +342,35 @@ { return $this->_label; } + + /** + * Sets a fragment identifier + * + * @param string $fragmentIdentifier new fragment identifier + * @return Zend_Navigation_Page fluent interface, returns self + * @throws Zend_Navigation_Exception if empty/no string is given + */ + public function setFragmentIdentifier($fragmentIdentifier) + { + if (null !== $fragmentIdentifier && !is_string($fragmentIdentifier)) { + require_once 'Zend/Navigation/Exception.php'; + throw new Zend_Navigation_Exception( + 'Invalid argument: $fragmentIdentifier must be a string or null'); + } + + $this->_fragmentIdentifier = $fragmentIdentifier; + return $this; + } + + /** + * Returns fragment identifier + * + * @return string|null fragment identifier + */ + public function getFragmentIdentifier() + { + return $this->_fragmentIdentifier; + } /** * Sets page id @@ -1090,20 +1133,21 @@ return array_merge( $this->getCustomProperties(), array( - 'label' => $this->getlabel(), - 'id' => $this->getId(), - 'class' => $this->getClass(), - 'title' => $this->getTitle(), - 'target' => $this->getTarget(), - 'rel' => $this->getRel(), - 'rev' => $this->getRev(), - 'order' => $this->getOrder(), - 'resource' => $this->getResource(), - 'privilege' => $this->getPrivilege(), - 'active' => $this->isActive(), - 'visible' => $this->isVisible(), - 'type' => get_class($this), - 'pages' => parent::toArray() + 'label' => $this->getlabel(), + 'fragmentIdentifier' => $this->getFragmentIdentifier(), + 'id' => $this->getId(), + 'class' => $this->getClass(), + 'title' => $this->getTitle(), + 'target' => $this->getTarget(), + 'rel' => $this->getRel(), + 'rev' => $this->getRev(), + 'order' => $this->getOrder(), + 'resource' => $this->getResource(), + 'privilege' => $this->getPrivilege(), + 'active' => $this->isActive(), + 'visible' => $this->isVisible(), + 'type' => get_class($this), + 'pages' => parent::toArray() )); } Index: library/Zend/Navigation/Page/Uri.php =================================================================== --- library/Zend/Navigation/Page/Uri.php (revision 24362) +++ library/Zend/Navigation/Page/Uri.php (working copy) @@ -74,12 +74,25 @@ /** * Returns href for this page + * + * Includes the fragment identifier if it is set. * * @return string */ public function getHref() { - return $this->getUri(); + $uri = $this->getUri(); + + $fragmentIdentifier = $this->getFragmentIdentifier(); + if (null !== $fragmentIdentifier) { + if ('#' == substr($uri, -1)) { + return $uri . $fragmentIdentifier; + } else { + return $uri . '#' . $fragmentIdentifier; + } + } + + return $uri; } // Public methods: Index: library/Zend/Navigation/Page/Mvc.php =================================================================== --- library/Zend/Navigation/Page/Mvc.php (revision 24362) +++ library/Zend/Navigation/Page/Mvc.php (working copy) @@ -216,6 +216,12 @@ $this->getRoute(), $this->getResetParams()); + // Add the fragment identifier if it is set + $fragmentIdentifier = $this->getFragmentIdentifier(); + if (null !== $fragmentIdentifier) { + $url .= '#' . $fragmentIdentifier; + } + return $this->_hrefCache = $url; }