Zend_Navigation
とZend_Navigation_Container
を再帰的に削除します。
はZend_Navigation_Container
を拡張My_Navigation_Container
を作成します。
abstract class My_Navigation_Container extends Zend_Navigation_Container
{
/**
* Remove page(s) matching $property == $value
*
* @param string $property
* @param mixed $value
* @param bool $all
* @return My_Navigation_Container
*/
public function removeBy($property, $value, $all = false)
{
$pages = array();
if ($all) {
$pages = $this->findAllBy($property, $value);
} else {
if ($page = $this->findOneBy($property, $value)) {
$pages[] = $page;
}
}
foreach ($pages as $page) {
$this->removePageRecursive($page);
}
return $this;
}
/**
* Recursively removes the given page from the container
*
* @param Zend_Navigation_Page $page
* @return boolean
*/
public function removePageRecursive(Zend_Navigation_Page $page)
{
if ($this->removePage($page)) {
return true;
}
$iterator = new RecursiveIteratorIterator($this, RecursiveIteratorIterator::SELF_FIRST);
foreach ($iterator as $pageContainer) {
if ($pageContainer->removePage($page)) {
return true;
}
}
return false;
}
}
My_Navigation_Container
を拡張Zend_Navigation
のコピーを作成します。
class My_Navigation extends My_Navigation_Container
{
/**
* Creates a new navigation container
*
* @param array|Zend_Config $pages [optional] pages to add
* @throws Zend_Navigation_Exception if $pages is invalid
*/
public function __construct($pages = null)
{
if (is_array($pages) || $pages instanceof Zend_Config) {
$this->addPages($pages);
} elseif (null !== $pages) {
throw new Zend_Navigation_Exception('Invalid argument: $pages must be an array, an instance of Zend_Config, or null');
}
}
}