protected function beforeAction($action) { if (parent::beforeAction($action)) { //print_r(Yii::app()->authManager->checkObject('list', Yii::app()->user->id)); $loginPage = $this->getModule() != null && $this->getModule()->getId() == 'user' && $this->getId() == 'user' && $action->getId() == 'login'; if (!Yii::app()->user->checkAccess('showAdminPanel')) { if (!$loginPage) { $errorPage = $this->getModule() == null && $this->getId() == 'static' && $action->getId() == 'error'; $logoutPage = $this->getModule() != null && $this->getModule()->getId() == 'user' && $this->getId() == 'user' && $action->getId() == 'logout'; if (Yii::app()->user->isGuest && !Yii::app()->request->isAjaxRequest && $action->getId() != 'captcha') { Yii::app()->user->setReturnUrl(Yii::app()->request->url); Yii::app()->user->loginRequired(); } else { if (!$errorPage && !$logoutPage) { $link = CHtml::link('авторизоваться заново', Yii::app()->createUrl('logout')); throw new CHttpException(403, '<div style="text-align: center;" class="alert alert-danger col-lg-7">Доступ к странице запрещен, попробуйте ' . $link . '.</div>'); } } } else { if (Yii::app()->user->returnUrl == '/') { Yii::app()->user->returnUrl = Yii::app()->createUrl(''); } } } else { if ($loginPage) { // переходим на главную Yii::app()->getRequest()->redirect(Yii::app()->createUrl('')); } } } return true; }
protected function beforeAction($action) { if (parent::beforeAction($action)) { // Пытаемся найти раздел меню по урлу if (Yii::app()->menu->setCurrent($this->getRoute(), $this->getActionParams(), $this->urlAlias)) { // заголовок страницы $this->caption = Yii::app()->menu->current->caption; // цепочка навигации $menu = Yii::app()->menu->current; while ($menu != null) { $this->breadcrumbs[$menu->caption == null ? $menu->name : $menu->caption] = $menu->getUrl(); $menu = $menu->getParent(); } $this->breadcrumbs = array_reverse($this->breadcrumbs); /** * @var Menu $menu */ $menu = Yii::app()->menu->current; // title if ($menu->title_teg != null) { $this->setPageTitle($menu->title_teg); } // keyword if ($menu->meta_keywords != null) { $this->setKeywords($menu->meta_keywords); } // description if ($menu->meta_description != null) { $this->setDescription($menu->meta_description); } else { $this->setDescription($menu->caption); } } return true; } return false; }