Example #1
0
 /**
  * Sets parent container
  *
  * @param  \Zend\Navigation\Container $parent  [optional] new parent to set.
  *                                            Default is null which will set
  *                                            no parent.
  * @return \Zend\Navigation\AbstractPage               fluent interface, returns self
  */
 public function setParent(Container $parent = null)
 {
     if ($parent === $this) {
         throw new Exception('A page cannot have itself as a parent');
     }
     // return if the given parent already is parent
     if ($parent === $this->_parent) {
         return $this;
     }
     // remove from old parent
     if (null !== $this->_parent) {
         $this->_parent->removePage($this);
     }
     // set new parent
     $this->_parent = $parent;
     // add to parent if page and not already a child
     if (null !== $this->_parent && !$this->_parent->hasPage($this, false)) {
         $this->_parent->addPage($this);
     }
     return $this;
 }