/** * Bootstrap method to be called during application bootstrap stage. * @param \yii\web\Application $app the application currently running */ public function bootstrap($app) { $app->set($this->id, $this); Yii::$container->set('gromver\\models\\fields\\EditorField', ['controller' => 'grom/media/manager']); Yii::$container->set('gromver\\models\\fields\\MediaField', ['controller' => 'grom/media/manager']); Yii::$container->set('gromver\\modulequery\\ModuleQuery', ['cache' => $app->cache, 'cacheDependency' => new ExpressionDependency(['expression' => '\\Yii::$app->getModulesHash()'])]); Yii::$container->set('gromver\\platform\\frontend\\components\\MenuMap', ['cache' => $app->cache, 'cacheDependency' => Table::dependency(MenuItem::tableName())]); /** @var MenuManager $manager */ $manager = \Yii::createObject(MenuManager::className()); $rules = [$manager]; if (is_array($this->blockModules) && count($this->blockModules)) { $rules['grom/<module:(' . implode('|', $this->blockModules) . ')><path:(/.*)?>'] = 'grom/default/page-not-found'; //блокируем доступ к контент модулям напрямую } $app->urlManager->addRules($rules, false); //вставляем в начало списка $app->set('menuManager', $manager); ModuleQuery::instance()->implement('\\gromver\\platform\\common\\interfaces\\BootstrapInterface')->invoke('bootstrap', [$app]); }
public function init() { parent::init(); if (empty($this->type)) { throw new InvalidConfigException(Yii::t('gromver.platform', 'Menu type must be set.')); } $this->language or $this->language = Yii::$app->language; $this->_rawItems = Yii::$app->db->cache(function ($db) { return MenuItem::find()->type($this->type)->published()->language($this->language)->asArray()->orderBy('lft')->all($db); }, $this->cacheDuration, Table::dependency(MenuItem::tableName())); $i = 0; $this->_items = $this->prepareMenuItems($i, 2); }