public function indexAction() { $url = $this->getRequest()->getPathInfo(); $navigation = Site_Service_Menu::getInstance()->getNavigation(); $page = $navigation->findOneByUri($url); if (!$page) { $this->forward('notFound', 'error'); return; } $this->view->page = $page; }
public function preDispatch() { parent::preDispatch(); $navigation = Site_Service_Menu::getInstance()->getNavigation(); $controller = $this->getRequest()->getControllerName(); $module = $this->getRequest()->getModuleName(); $url = $this->getRequest()->getPathInfo(); $page = $navigation->findOneByUri($url); $this->view->currentPage = $page; if ($page) { $page->setActive(true); } if ($page && !empty($page->resource)) { $resource = $page->resource; } else { $resource = Site_Acl::RESOURCE_PUBLIC; } // Проверяем, авторизован ли пользователь $role = Site_Service_Auth::getInstance()->getUser()->getRole(); $acl = Site_Acl::getInstance(); // К этим 2 контроллерам доступ есть всегда if ($controller != 'error' && $controller != 'auth' && $module == 'default') { $allowed = $acl->isAllowed($role, $resource); if (!$allowed) { $url = $this->getRequest()->getRequestUri(); if (Site_Service_Auth::getInstance()->isLoggedIn()) { $this->forward('deny', 'error'); } else { $this->redirect('auth/login?from=' . urlencode($url) . '&warn=1'); } return; } } // Меню $this->view->navigation($navigation); $this->view->navigation()->setAcl($acl)->setRole($role); // login $this->view->loggedUser = Site_Service_Auth::getInstance()->getUser(); }
public static function getInstance() { return self::$instance ? self::$instance : (self::$instance = new self()); }