/** * Returns whether page should be considered active or not * * This method will compare the page properties against the request object * that is found in the front controller. * * @param bool $recursive [optional] whether page should be considered * active if any child pages are active. Default is * false. * @return bool whether page should be considered active or not */ public function isActive($recursive = false) { if (!$this->_active) { $front = FrontController::getInstance(); $reqParams = $front->getRequest()->getParams(); if (!array_key_exists('module', $reqParams)) { $reqParams['module'] = $front->getDefaultModule(); } $myParams = $this->_params; if (null !== $this->_module) { $myParams['module'] = $this->_module; } else { $myParams['module'] = $front->getDefaultModule(); } if (null !== $this->_controller) { $myParams['controller'] = $this->_controller; } else { $myParams['controller'] = $front->getDefaultControllerName(); } if (null !== $this->_action) { $myParams['action'] = $this->_action; } else { $myParams['action'] = $front->getDefaultAction(); } if (count(array_intersect_assoc($reqParams, $myParams)) == count($myParams)) { $this->_active = true; return true; } } return parent::isActive($recursive); }
/** * Returns whether page should be considered active or not * * This method will compare the page properties against the route matches * composed in the object. * * @param bool $recursive [optional] whether page should be considered * active if any child pages are active. Default is * false. * @return bool whether page should be considered active or not */ public function isActive($recursive = false) { if (!$this->active) { $reqParams = array(); if ($this->routeMatch instanceof RouteMatch) { $reqParams = $this->routeMatch->getParams(); } $myParams = $this->params; if (null !== $this->controller) { $myParams['controller'] = $this->controller; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ $myParams['controller'] = 'index'; } if (null !== $this->action) { $myParams['action'] = $this->action; } else { /** * @todo In ZF1, this was configurable and pulled from the front controller */ $myParams['action'] = 'action'; } if (count(array_intersect_assoc($reqParams, $myParams)) == count($myParams)) { $this->active = true; return true; } } return parent::isActive($recursive); }