Example #1
0
 public function init()
 {
     parent::init();
     Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, function ($event) {
         $event->sender->view->params['pagelabel'] = 'User Management System';
     });
 }
Example #2
0
 public function bootstrap($app)
 {
     \Yii::$classMap = array_merge(\Yii::$classMap, ['yii\\grid\\CheckboxColumn' => '@yii/adminUi/widget/CheckboxColumn.php', 'yii\\grid\\ActionColumn' => '@yii/adminUi/widget/ActionColumn.php']);
     $app->set('view', ['class' => 'yii\\web\\View', 'theme' => ['pathMap' => ['@backend/views' => '@backend/themes/adminui']]]);
     $app->set('assetManager', ['class' => 'yii\\web\\AssetManager', 'bundles' => ['yii\\widgets\\ActiveFormAsset' => ['js' => [], 'depends' => ['yii\\adminUi\\assetsBundle\\AdminUiActiveForm']], 'yii\\grid\\GridViewAsset' => ['depends' => ['app\\assets\\AppAsset']]], 'linkAssets' => true]);
     Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, function ($event) {
         if (in_array($event->action->id, ['login', 'forgot', 'reset-password']) && in_array('backend', explode("\\", $event->sender->className()))) {
             $event->sender->layout = '//blank';
         }
     });
 }
Example #3
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (!Yii::$app instanceof Application) {
         return;
     }
     Event::on(Controller::className(), 'beforeAction', [$this, 'beforeActionAccess']);
     if ($this->removeDeniedLinks) {
         Event::on(Response::className(), 'afterPrepare', [$this, 'responseAfterPrepare']);
     }
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['modelClass', 'formModelClass', 'baseClass', 'controllerClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class must not be equal to Model Class.'], [['baseClass'], 'required'], [['modelClass', 'modelClass', 'controllerClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters are allowed.'], [['baseClass'], 'match', 'pattern' => '/^[\\w\\\\]+$/', 'message' => 'Only word characters and backslashes are allowed.'], [['controllerClass', 'searchModelClass'], 'validateNewClass'], [['modelClass', 'formModelClass'], 'validateModelClass', 'skipOnEmpty' => false], [['baseClass', 'modelClass'], 'validateClass', 'params' => ['extends' => Model::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], function ($field) {
         if ($this->{$field}) {
             if (!$this->formModelClass) {
                 $this->addError('formModelClass', 'formModelClass required');
             }
             if (!$this->searchModelClass) {
                 $this->addError('searchModelClass', 'searchModelClass required');
             }
         }
     }]]);
 }
 public function bootstrap($app)
 {
     /*@var $app Application*/
     if ($app->request->get('blankLayout') === 'true') {
         Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, function ($event) {
             if (file_exists(Yii::getAlias('@app') . DIRECTORY_SEPARATOR . 'composer.json')) {
                 $replace = '@app';
             } else {
                 $replace = '@app/..';
             }
             $event->action->controller->layout = $replace . str_replace(realpath(Yii::getAlias($replace)), '', str_replace("\\", "/", __DIR__ . DIRECTORY_SEPARATOR . 'widgets' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'layouts' . DIRECTORY_SEPARATOR . 'blank.php'));
         });
     }
 }
Example #6
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [
         [['controllerClass', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'],
         [['modelClass', 'controllerClass', 'baseControllerClass', 'indexWidgetType'], 'required'],
         [['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class must not be equal to Model Class.'],
         [['modelClass', 'controllerClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'],
         [['modelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]],
         [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]],
         [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'],
         [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'],
         [['controllerClass', 'searchModelClass'], 'validateNewClass'],
         [['indexWidgetType'], 'in', 'range' => ['grid', 'list']],
         [['modelClass'], 'validateModelClass'],
         [['enableI18N'], 'boolean'],
         [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false],
         ['viewPath', 'safe'],
     ]);
 }
Example #7
0
 public function bootstrap($app)
 {
     $events = [Controller::EVENT_BEFORE_ACTION];
     foreach ($events as $eventName) {
         Event::on(Controller::className(), $eventName, function ($event) use($app, $eventName) {
             Libs::mkView($app, $eventName, $event);
         });
     }
     $events = [ActiveRecord::EVENT_AFTER_INSERT, ActiveRecord::EVENT_BEFORE_UPDATE, ActiveRecord::EVENT_BEFORE_DELETE];
     $res0 = false;
     foreach ($events as $eventName) {
         Event::on(ActiveRecord::className(), $eventName, function ($event) use($app, $eventName) {
             $model = $event->sender;
             $res0 = Libs::mkVersion($app, $eventName, $model);
         });
     }
     if ($res0) {
         $events = [ActiveRecord::EVENT_AFTER_UPDATE, ActiveRecord::EVENT_AFTER_DELETE];
         foreach ($events as $eventName) {
             Event::on(ActiveRecord::className(), $eventName, function ($event) use($app, $eventName, $res0) {
                 $res = true;
                 $model = $event->sender;
                 foreach ($model->attributes as $a => $v) {
                     $m = $res0[1];
                     if ($eventName == ActiveRecord::EVENT_AFTER_UPDATE) {
                         $res = $m[$a] != $v ? false : $res;
                     } elseif ($eventName == ActiveRecord::EVENT_AFTER_DELETE) {
                         $res = $m[$a] != null ? false : $res;
                     }
                 }
                 if (!$res) {
                     $route = Route::findOne($res0[0]);
                     if ($route) {
                         $route->delete();
                     }
                 }
             });
         }
     }
 }
 public function rules()
 {
     return ArrayHelper::merge(parent::rules(), [[['columns'], MultipleModelValidator::className(), 'baseModel' => WidgetsCrud::className(), 'skipOnEmpty' => true], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'filter', 'filter' => 'trim'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'required'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['baseControllerFrontendClass', 'baseControllerBackendClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.']]);
 }
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param \yii\web\UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|bool the parsing result. The route and the parameters are returned as an array.
  * @throws ForbiddenHttpException
  */
 public function parseRequest($manager, $request)
 {
     $menuMap = $this->menuManager->getMenuMap();
     if (!($pathInfo = $request->getPathInfo() or $pathInfo = ($mainMenu = $menuMap->getMainMenu()) ? $mainMenu->path : null)) {
         return false;
     }
     // помечаем как активные все пункты меню которые ссылаются на тотже урл что в запросе
     $this->menuManager->setActiveMenuIds($menuMap->getMenuIdsByLink($request->getUrl()));
     // ищем пункт меню, чей путь совпадает с путем в запросе
     if ($menu = $menuMap->getMenuByPathRecursive($pathInfo)) {
         // определяем в каком контексте ("Точный" или "Подходящий") рассматривать активное меню
         $menu->setContext($menu->path === $pathInfo ? MenuItem::CONTEXT_PROPER : MenuItem::CONTEXT_APPLICABLE);
         // устанавливаем найденный пункт меню в качестве активного
         $this->menuManager->setActiveMenu($menu);
         // добавляем данный пункт в список активных пунктов меню
         $this->menuManager->addActiveMenuId($menu->id);
         if ($menu->getContext() === MenuItem::CONTEXT_PROPER) {
             //при "точном" совпадении, метаданные меню перекрывают метаднные контроллера
             Yii::$app->getView()->on(View::EVENT_BEGIN_PAGE, [$this, 'applyMetaData']);
         } else {
             //при "подходящем" устанавливаются по умолчанию
             $this->applyMetaData();
         }
     } else {
         return false;
     }
     // устанавливаем макет приложению
     Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, [$this, 'applyLayout']);
     // Проверка на доступ к пунтку меню
     if (!empty($menu->access_rule) && !Yii::$app->user->can($menu->access_rule)) {
         if (Yii::$app->user->getIsGuest()) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('gromver.platform', 'You have no rights for access to this section of the site.'));
         }
     }
     if ($menu->getContext() === MenuItem::CONTEXT_PROPER) {
         // при "точном" контексте пункта меню, возвращаем роут на компонент
         return $menu->parseUrl();
     } else {
         /*
          * при "подходящем" контексте пункта меню, необходимо на основании оставшейся части пути
          * и информации из пункта меню маршрутизировать приложение
          */
         $requestRoute = substr($pathInfo, mb_strlen($menu->path) + 1);
         list($menuRoute, $menuParams) = $menu->parseUrl();
         $requestInfo = new MenuRequestInfo(['menuMap' => $menuMap, 'menuRoute' => $menuRoute, 'menuParams' => $menuParams, 'requestRoute' => $requestRoute, 'requestParams' => $request->getQueryParams()]);
         foreach ($this->_parseUrlRules as $rule) {
             if ($result = $rule->process($requestInfo, $this)) {
                 return $result;
             }
         }
         return false;
     }
 }
Example #10
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['controllerClass', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['modelClass', 'controllerClass', 'baseControllerClass'], 'required'], [['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class 必须继承自 Model Class.'], [['modelClass', 'controllerClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => '只有字母和"\\"允许使用.'], [['modelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => '控制器名字必须以:"Controller".结尾'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => '控制器名字必须是大写字母开头.'], [['controllerClass', 'searchModelClass'], 'validateNewClass'], [['modelClass'], 'validateModelClass'], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false], ['viewPath', 'safe']]);
 }
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['db', 'nsModel', 'viewPath', 'queryNs', 'nsController', 'nsSearchModel', 'tableName', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['tableName', 'baseControllerClass', 'indexWidgetType', 'db'], 'required'], [['tableName'], 'match', 'pattern' => '/^(\\w+\\.)?([\\w\\*]+)$/', 'message' => 'Only word characters, and optionally an asterisk and/or a dot are allowed.'], [['tableName'], 'validateTableName'], [['modelClass', 'baseControllerClass', 'searchModelClass', 'db', 'queryClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['db'], 'validateDb'], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'], [['indexWidgetType'], 'in', 'range' => ['grid', 'list']], [['enableI18N', 'generateRelations', 'generateSearchModel', 'pluralize', 'expandable', 'exportable', 'pdf', 'loggedUserOnly'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false], [['viewPath', 'skippedRelations', 'skippedColumns', 'controllerClass', 'blameableValue', 'nameAttribute', 'hiddenColumns', 'createdAt', 'updatedAt', 'createdBy', 'updatedBy', 'UUIDColumn'], 'safe']]);
 }
Example #12
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['moduleID', 'controllerID', 'actions', 'formActions', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['controllerID', 'baseControllerClass'], 'required'], [['controllerID'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-\\/]*$/', 'message' => 'Only a-z, 0-9, dashes (-) and slashes (/) are allowed.'], [['actions', 'formActions'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-,\\s]*$/', 'message' => 'Only a-z, 0-9, dashes (-), spaces and commas are allowed.'], [['baseControllerClass', 'modelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['scenarioName'], 'match', 'pattern' => '/^[\\w\\-]+$/', 'message' => 'Only word characters and dashes are allowed.'], [['modelClass'], 'validateClass', 'params' => ['extends' => Model::className()]], [['moduleID'], 'validateModuleID']]);
 }
Example #13
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['loginModelClass', 'controllerClass', 'viewPath'], 'filter', 'filter' => 'trim'], [['loginModelClass', 'controllerClass', 'viewPath'], 'required'], [['loginModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['loginModelClass'], 'validateClass', 'params' => ['extends' => Model::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'], [['controllerClass'], 'validateNewClass'], [['viewPath'], 'match', 'pattern' => '/^@?\\w+[\\-\\/\\w]*$/', 'message' => 'Only word characters, dashes, slashes and @ are allowed.'], [['viewPath'], 'validatePath'], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false]]);
 }
Example #14
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['modelClass'], 'required'], [['modelClass', 'baseControllerClass', 'extraActions'], 'filter', 'filter' => 'trim'], [['modelClass', 'controllerClass', 'baseControllerClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['modelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'], [['controllerClass'], 'validateNewClass'], [['modelClass'], 'validateModelClass'], [['controllerActionIndexEnabled', 'controllerActionCreateEnabled', 'controllerActionUpdateEnabled', 'controllerActionDeleteEnabled', 'controllerActionApproveEnabled', 'controllerActionDisapproveEnabled', 'controllerActionDeleteSelectedEnabled', 'controllerActionApproveSelectedEnabled', 'controllerActionDisapproveSelectedEnabled', 'controllerActionDetailViewEnabled'], 'boolean', 'on' => 'controller'], ['headingTitle', 'string', 'on' => 'index'], ['columns', 'safe', 'on' => 'index'], [['toolbarCreateButtonEnabled', 'toolbarApproveButtonEnabled', 'toolbarDisapproveButtonEnabled', 'toolbarDeleteButtonEnabled', 'toolbarRefreshButtonEnabled', 'checkboxColumnEnabled', 'actionColumnEnabled', 'actionApproveEnabled', 'actionDisapproveEnabled', 'idColumnEnabled', 'createdColumnEnabled', 'updatedColumnEnabled', 'detailColumnEnabled', 'pjax', 'condensed', 'hover', 'showPageSummary', 'resizableColumns', 'floatHeader', 'perfectScrollbar', 'toggleData', 'showHeader', 'bootstrap', 'bordered', 'striped'], 'boolean', 'on' => 'index'], ['columns', 'safe', 'on' => 'index'], ['columns', 'safe', 'on' => 'index']]);
 }
Example #15
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return [[['template'], 'required', 'message' => 'A code template must be selected.'], [['template'], 'validateTemplate'], [['controllerClass', 'modelClass', 'baseControllerClass', 'baseModelClass'], 'filter', 'filter' => 'trim'], [['modelClass', 'controllerClass', 'baseControllerClass', 'baseModelClass'], 'required'], [['modelClass', 'controllerClass', 'baseControllerClass', 'baseModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseModelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerClass'], 'match', 'pattern' => '/Controller$/', 'message' => 'Controller class name must be suffixed with "Controller".'], [['controllerClass'], 'match', 'pattern' => '/(^|\\\\)[A-Z][^\\\\]+Controller$/', 'message' => 'Controller class name must start with an uppercase letter.'], [['controllerClass', 'modelClass'], 'validateNewClass'], [['baseModelClass'], 'validateBaseModelClass'], [['enableI18N', 'isImage'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false], ['viewPath', 'safe']];
 }
Example #16
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(\yii\gii\Generator::rules(), [[['moduleID', 'controllerID', 'modelClass', 'searchModelClass', 'baseControllerClass'], 'filter', 'filter' => 'trim'], [['modelClass', 'controllerID', 'baseControllerClass', 'indexWidgetType'], 'required'], [['searchModelClass'], 'compare', 'compareAttribute' => 'modelClass', 'operator' => '!==', 'message' => 'Search Model Class must not be equal to Model Class.'], [['modelClass', 'baseControllerClass', 'searchModelClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['modelClass'], 'validateClass', 'params' => ['extends' => BaseActiveRecord::className()]], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]], [['controllerID'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-\\/]*$/', 'message' => 'Only a-z, 0-9, dashes (-) and slashes (/) are allowed.'], [['searchModelClass'], 'validateNewClass'], [['controllerClass'], 'filter', 'filter' => function () {
         return $this->getControllerClass();
     }, 'skipOnEmpty' => false], [['indexWidgetType'], 'in', 'range' => ['grid', 'list']], [['modelClass'], 'validateModelClass'], [['moduleID'], 'validateModuleID'], [['enableI18N'], 'boolean'], [['messageCategory'], 'validateMessageCategory', 'skipOnEmpty' => false]]);
 }
Example #17
0
use nullref\core\interfaces\IAdminController;

/**
 * <?php 
echo $controllerClass;
?>
 implements the CRUD actions for <?php 
echo $modelClass;
?>
 model.
 */
class <?php 
echo $controllerClass;
?>
 extends <?php 
echo StringHelper::basename(\yii\web\Controller::className());
?>
 implements IAdminController
{
    public function behaviors()
    {
        return [
            'verbs' => [
                'class' => VerbFilter::className(),
                'actions' => [
                    'delete' => ['POST'],
                ],
            ],
        ];
    }
Example #18
0
 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param \yii\web\UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|bool the parsing result. The route and the parameters are returned as an array.
  * @throws ForbiddenHttpException
  */
 public function parseRequest($manager, $request)
 {
     if (!($pathInfo = $request->getPathInfo() or $pathInfo = $this->getMenuMap()->getMainPagePath())) {
         return false;
     }
     //Пункт 2
     $this->_activeMenuIds = array_keys($this->getMenuMap()->getLinks(), $request->getUrl());
     if ($this->_menu = $this->getMenuMap()->getMenuByPath($pathInfo)) {
         //Пункт 1.1
         $this->_activeMenuIds[] = $this->_menu->id;
         $this->_menu->setContext(MenuItem::CONTEXT_PROPER);
         //при полном совпадении метаданные меню перекрывают метаднные контроллера
         Yii::$app->getView()->on(View::EVENT_BEGIN_PAGE, [$this, 'applyMetaData']);
     } elseif ($this->_menu = $this->getMenuMap()->getApplicableMenuByPath($pathInfo)) {
         //Пункт 1.2
         $this->_activeMenuIds[] = $this->_menu->id;
         $this->_menu->setContext(MenuItem::CONTEXT_APPLICABLE);
         $this->applyMetaData();
     } else {
         return false;
     }
     // устанавливаем макет приложению
     Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, [$this, 'applyLayout']);
     //Проверка на доступ к пунтку меню
     if (!empty($this->_menu->access_rule) && !Yii::$app->user->can($this->_menu->access_rule)) {
         if (Yii::$app->user->getIsGuest()) {
             Yii::$app->user->loginRequired();
         } else {
             throw new ForbiddenHttpException(Yii::t('gromver.platform', 'You have no rights for access to this section of the site.'));
         }
     }
     if ($this->_menu->getContext() === MenuItem::CONTEXT_PROPER) {
         return $this->_menu->parseUrl();
     } else {
         $requestRoute = substr($pathInfo, mb_strlen($this->_menu->path) + 1);
         list($menuRoute, $menuParams) = $this->_menu->parseUrl();
         $requestInfo = new MenuRequest(['menuMap' => $this->getMenuMap(), 'menuRoute' => $menuRoute, 'menuParams' => $menuParams, 'requestRoute' => $requestRoute, 'requestParams' => $request->getQueryParams()]);
         foreach ($this->_parseUrlRules as $rule) {
             if ($result = $rule->process($requestInfo, $this)) {
                 return $result;
             }
         }
         return false;
     }
 }
Example #19
0
 /**
  * @inheritdoc
  */
 public function rules()
 {
     return array_merge(parent::rules(), [[['restControllerID', 'prefixRoute', 'baseControllerClass'], 'trim'], [['restControllerID', 'prefixRoute'], 'match', 'pattern' => '/^[a-z][a-z0-9\\-\\/]*$/', 'message' => 'Only a-z, 0-9, dashes (-) and slashes (/) are allowed.'], [['baseControllerClass'], 'match', 'pattern' => '/^[\\w\\\\]*$/', 'message' => 'Only word characters and backslashes are allowed.'], [['baseControllerClass'], 'validateClass', 'params' => ['extends' => Controller::className()]]]);
 }
Example #20
0
<?php

use yii\base\Event;
use yii\web\Controller;
$params = (require __DIR__ . '/params.php');
Yii::setAlias('app', dirname(__DIR__));
Event::on(Controller::className(), Controller::EVENT_BEFORE_ACTION, function ($event) {
    if ($user = Yii::$app->user->identity) {
        $user->last_visit = (new DateTime())->format('Y-m-d H:i:s');
        $user->save(false);
    }
});
$config = ['id' => 'basic', 'language' => 'ru-RU', 'viewPath' => dirname(__DIR__) . '/modules/main/views', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log', 'admin'], 'extensions' => require_once Yii::getAlias('@app/config/extensions.php'), 'as access' => ['class' => 'mdm\\admin\\classes\\AccessControl', 'allowActions' => ['main/*', 'blog/*', 'user/user/login', 'user/user/logout', '*', 'admin/*', 'debug/*']], 'modules' => ['backend' => ['class' => 'app\\modules\\backend\\Module', 'layout' => 'main', 'modules' => ['blog' => ['class' => 'obuhovski\\blog\\backend\\Module'], 'comments' => ['class' => 'obuhovski\\comments\\backend\\Module']]], 'admin' => ['class' => 'mdm\\admin\\Module'], 'main' => ['class' => 'app\\modules\\main\\Module'], 'user' => ['class' => 'obuhovski\\user\\frontend\\Module'], 'blog' => ['class' => 'obuhovski\\blog\\frontend\\Module']], 'components' => ['assetManager' => ['linkAssets' => true], 'authClientCollection' => ['class' => 'yii\\authclient\\Collection', 'clients' => ['google' => ['class' => 'yii\\authclient\\clients\\GoogleOAuth', 'clientId' => '338669426716-6jqajl5vjk69hqf762fa3h978o9umb78.apps.googleusercontent.com', 'clientSecret' => '8i8TqWAhNOrOaeTgVkAJ8Vnj', 'returnUrl' => 'http://my-site.dev/user/auth/auth?authclient=google'], 'facebook' => ['class' => 'yii\\authclient\\clients\\Facebook', 'clientId' => '581024815383856', 'clientSecret' => 'dd67420e30f19051f9185e42fcaf79b9'], 'VKontakte' => ['class' => 'yii\\authclient\\clients\\VKontakte', 'clientId' => '5316979', 'clientSecret' => 'nqg9oQrwmgzDGMDyF65M']]], 'eauth' => ['class' => 'nodge\\eauth\\EAuth', 'popup' => true, 'cache' => false, 'cacheExpire' => 0, 'httpClient' => [], 'services' => ['google' => ['class' => 'nodge\\eauth\\services\\GoogleOAuth2Service', 'clientId' => '338669426716-6jqajl5vjk69hqf762fa3h978o9umb78.apps.googleusercontent.com', 'clientSecret' => '8i8TqWAhNOrOaeTgVkAJ8Vnj', 'title' => 'Google'], 'facebook' => ['class' => 'nodge\\eauth\\services\\FacebookOAuth2Service', 'clientId' => '961319667270316', 'clientSecret' => 'b1f26ae6a392c49283f7a942c1702e3d'], 'vkontakte' => ['class' => 'nodge\\eauth\\services\\VKontakteOAuth2Service', 'clientId' => '5316979', 'clientSecret' => 'nqg9oQrwmgzDGMDyF65M']]], 'i18n' => ['translations' => ['eauth' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@eauth/messages']]], 'request' => ['cookieValidationKey' => 'G_h-9Qw_MFigoDS8FHjoEiFHAxoqkI4s'], 'cache' => ['class' => 'yii\\caching\\FileCache'], 'user' => ['identityClass' => 'obuhovski\\user\\models\\User', 'enableAutoLogin' => true, 'loginUrl' => '/user/auth/login'], 'errorHandler' => ['errorAction' => 'main/site/error'], 'mailer' => ['class' => 'yii\\swiftmailer\\Mailer', 'useFileTransport' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'db' => require __DIR__ . '/db.php', 'authManager' => ['class' => 'yii\\rbac\\DbManager'], 'urlManager' => ['enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => ['/' => 'main/site/index']]], 'params' => $params];
if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = ['class' => 'yii\\debug\\Module'];
    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = ['class' => 'yii\\gii\\Module'];
}
return $config;