/** * Поиск моделей меню * @return bool */ protected function findModels() { $parentQuery = MenuModel::find()->published(); if ($this->parentId) { $parent = $parentQuery->where(["id" => $this->parentId])->one(); } elseif ($this->parentCode) { $parent = $parentQuery->where(["code" => $this->parentCode])->one(); } if (empty($parent)) { return false; } if (!empty($this->parentLink)) { $parent = $parent->children()->published()->where(["link" => $this->parentLink])->one(); if (!$parent) { return false; } } $this->parentLevel = $parent->level; $level = $parent->level + $this->level; $this->models = $parent->children()->published()->andWhere("level <= :level", [":level" => $level])->all(); return true; }
<?php use app\modules\main\models; return ['controllerMap' => ['migrate' => ['migrationLookup' => ['@webapp/modules/main/migrations']]], 'modules' => ['main' => ['class' => app\modules\main\Main::className(), 'controllerNamespace' => 'app\\modules\\main\\controllers', 'components' => ['tagsConverter' => \common\components\TagsConverter::className(), 'sphinxUrlService' => \app\modules\main\components\SphinxUrlService::className(), 'sitemap' => ["class" => \app\modules\main\sitemap\Sitemap::className(), "definition" => [['class' => 'app\\modules\\main\\models\\Pages', 'urlCreate' => function ($model) { return Yii::$app->urlManager->createUrl(['/main/pages/index', 'model' => $model]); }]]], 'config' => ['class' => \app\modules\main\components\Config::className()], 'treeFinder' => ['class' => \common\components\TreeFinder::className()], 'blocksProvider' => ['class' => \app\modules\main\components\BlocksProvider::className()]], 'modules' => ['admin' => ['class' => app\modules\main\modules\admin\Admin::className(), 'controllerNamespace' => 'app\\modules\\main\\modules\\admin\\controllers', 'menuItems' => function () { return [['label' => Yii::t('main/app', 'Main module'), 'icon' => 'glyphicon glyphicon-home', 'items' => [['label' => Yii::t('main/app', 'Pages'), 'url' => ['/admin/main/pages'], "permission" => ["listModels", ["model" => Yii::createObject(models\Pages::className())]]], ['label' => Yii::t('main/app', 'Menu'), 'url' => ['/admin/main/menu'], "permission" => ["listModels", ["model" => Yii::createObject(models\Menu::className())]]], ['label' => Yii::t('main/app', 'Users'), 'url' => ['/admin/main/user'], "permission" => ["listModels", ["model" => Yii::createObject(models\User::className())]]], ['label' => Yii::t('main/app', 'FileManager'), 'url' => ['/admin/main/file-manager'], "permission" => ["fileManager"]], ['label' => Yii::t('main/app', 'Templates'), 'url' => ['/admin/main/template'], "permission" => ["rootAccess"]], ['label' => Yii::t('main/app', 'Includes'), 'url' => ['/admin/main/includes'], "permission" => ["listModels", ["model" => Yii::createObject(models\Includes::className())]]], ['label' => Yii::t('main/app', 'Include Groups'), 'url' => ['/admin/main/include-group'], "permission" => ["listModels", ["model" => Yii::createObject(models\IncludeGroup::className())]]], ['label' => Yii::t('main/app', 'Comments'), 'url' => ['/admin/main/comments'], "permission" => ["listModels", ["model" => Yii::createObject(models\Comments::className())]]], ['label' => Yii::t('main/app', 'Reviews'), 'url' => ['/admin/main/review'], "permission" => ["listModels", ["model" => Yii::createObject(models\Review::className())]]], ['label' => Yii::t('main/app', 'Tools'), 'url' => ['/admin/main/tools'], "permission" => ["rootAccess"]], ['label' => Yii::t('main/app', 'Permission'), 'url' => ['/admin/main/permission'], "permission" => ["rootAccess"]], ['label' => Yii::t('main/app', 'Config'), 'url' => ['/admin/main/config'], "permission" => ["rootAccess"]]]]]; }]]]], 'components' => ['i18n' => ['translations' => ['main/*' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@webapp/modules/main/messages', 'fileMap' => ['main/app' => 'app.php']]]], 'urlManager' => ['rules' => ['user/<action:[A-z0-9_-]+>' => 'main/user/<action>', 'user' => 'main/user/profile', ['class' => '\\app\\modules\\main\\components\\PageUrlRule']]]]];
/** * Действия * @return array */ public function actions() { $class = Menu::className(); return ['index' => ['class' => crud\TAdmin::className(), 'modelClass' => $class], 'create' => ['class' => crud\TCreate::className(), 'modelClass' => $class, 'defaultAttrs' => ['target' => Menu::TARGET_SELF]], 'update' => ['class' => crud\TUpdate::className(), 'modelClass' => $class], 'view' => ['class' => crud\View::className(), 'modelClass' => $class], 'delete' => ['class' => crud\TDelete::className(), 'modelClass' => $class], 'groupdelete' => ['class' => crud\TGroupDelete::className(), 'modelClass' => $class], 'up' => ['class' => crud\TUp::className(), 'modelClass' => $class], 'down' => ['class' => crud\TDown::className(), 'modelClass' => $class], 'replace' => ['class' => crud\TReplace::className(), 'modelClass' => $class], 'editable' => ['class' => crud\XEditable::className(), 'modelClass' => $class]]; }