A module represents a sub-application which contains MVC elements by itself, such as
models, views, controllers, etc.
A module may consist of [[modules|sub-modules]].
[[components|Components]] may be registered with the module so that they are globally
accessible within the module.
/** * @inheritdoc * @throws InvalidConfigException */ public function init() { if (\Yii::$app->authManager === null) { throw new InvalidConfigException('You forgot configure the "authManager" component.'); } parent::init(); }
public function init() { parent::init(); if (!\Yii::$app->user->can('adminDashboard')) { throw new ForbiddenHttpException('Access denied'); } }
public function init() { parent::init(); if (!isset(Yii::$app->i18n->translations['forum'])) { Yii::$app->i18n->translations['forum'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'en', 'basePath' => '@backend/modules/forum/messages']; } }
public function init() { // Menu backend $this->backendMenu = [['label' => Yii::t('message', 'Message'), 'url' => ['/message/default'], 'access' => ['message/backend/default/*', 'message/backend/default/index']], ['label' => Yii::t('common', 'Setting'), 'url' => ['/common/setting', 'module' => 'message'], 'access' => ['common/setting']]]; parent::init(); // custom initialization code goes here }
public function init() { parent::init(); /*if ($app instanceof \yii\console\Application) { $$this->controllerNamespace; }*/ }
/** * Run the job. * * @param Job $job */ public function run(Job $job) { \Yii::info('Running job', 'yii2queue'); try { if ($job->isCallable()) { $retval = $job->runCallable(); } else { $retval = $this->module->runAction($job->route, $job->data); } } catch (\Exception $e) { if ($job->isCallable()) { if (isset($job->header['signature']) && isset($job->header['signature']['route'])) { $id = $job->id . " " . \yii\helpers\Json::encode($job->header['signature']['route']); } else { $id = $job->id . ' callable'; } } else { $id = $job->route; } \Yii::error("Fatal Error: Error running route '{$id}'. Message: {$e->getMessage()}", 'yii2queue'); throw new \yii\base\Exception("Error running route '{$id}'. Message: {$e->getMessage()}. File: {$e->getFile()}[{$e->getLine()}]. Stack Trace: {$e->getTraceAsString()}", 500); } if ($retval !== false) { \Yii::info('Deleting job', 'yii2queue'); $this->delete($job); } }
public function init() { parent::init(); if (is_null($this->attribute)) { throw new Exception("Module \"attribute\" attribute must be set"); } if (is_null($this->latitudeAttribute)) { throw new Exception("Module \"latitudeAttribute\" attribute must be set"); } if (is_null($this->longitudeAttribute)) { throw new Exception("Module \"longitudeAttribute\" attribute must be set"); } if (is_null($this->jsonAttribute)) { throw new Exception("Module \"jsonAttribute\" attribute must be set"); } if (is_null($this->class)) { $this->class = __NAMESPACE__ . '\\models\\Locations'; } $location = new $this->class(); $location->setAttributes(['destinationAttribute' => $this->attribute, 'latitudeAttribute' => $this->latitudeAttribute, 'longitudeAttribute' => $this->longitudeAttribute, 'jsonAttribute' => $this->jsonAttribute]); $this->location = $location; Event::on(Locations::className(), Locations::EVENT_ADD_LOCATION, [Locations::className(), 'addLocation']); Event::on(Locations::className(), Locations::EVENT_GET_LOCATION, [Locations::className(), 'getLocation']); return true; }
public function init() { parent::init(); if (\Yii::$app instanceof \yii\console\Application) { $this->controllerNamespace = 'common\\modules\\rbac\\commands'; } }
public function beforeAction($action) { if (parent::beforeAction($action)) { // Запретим доступ неавторизованным пользователям // TODO убрать запрет и сделать нормальные поведения if (Yii::$app->getUser()->isGuest) { throw new ForbiddenHttpException('У вас нет прав просматривать данную страницу.'); } if (isset($action->controller->breadcrumbItems)) { $action->controller->addBreadcrumbsItem(['label' => 'Личный кабинет', 'url' => ['/cabinet']]); $items = $action->controller->breadcrumbItems[$action->id]; if ($items === 'not add') { // Просто выходим и разрешаем выолнять Action return true; } if (is_array($items)) { foreach ($items as $item) { if (isset($item['url'])) { $action->controller->addBreadcrumbsItem(['label' => $item['label'], 'url' => $item['url']]); } else { $action->controller->addBreadcrumbsItem(['label' => $item['label']]); } } } else { $action->controller->addBreadcrumbsItem(['label' => $items]); } } else { $action->controller->addBreadcrumbsItem(['label' => 'Личный кабинет']); } return true; // or false if needed } else { return false; } }
/** * @inheritdoc */ protected function getModulePermissions(\yii\base\Module $module) { if ($module instanceof \humhub\components\Module) { return $module->getPermissions($this->contentContainer); } return []; }
/** * @inheritdoc */ public function init() { if (is_callable($this->userId)) { $this->userId = call_user_func($this->userId); } parent::init(); }
public function init() { parent::init(); // \Yii::$app->request->setAcceptableContentTypes(['application/json' => ['q' => 1]]); \Yii::$app->user->enableSession = false; Helper::handle_response(); }
/** * @inheritdoc */ public function init() { parent::init(); $handler = new \yii\web\ErrorHandler(['errorAction' => 'empresas/default/error', 'errorView' => '@app/modules/empresas/views/default/error.php']); Yii::$app->set('errorHandler', $handler); $handler->register(); }
/** * @inheritdoc */ public function init() { parent::init(); if ($this->userIdentityClass === null) { $this->userIdentityClass = \Yii::$app->getUser()->identityClass; } }
public function init() { parent::init(); Yii::$app->user->loginUrl = ['admin/login']; Yii::$app->user->identityClass = 'app\\modules\\admin\\identity\\Admin'; Yii::configure($this, $this->config()); }
/** * */ public function init() { $modulePathAlias = '@app/modules/' . $this->id; parent::init(); $this->controllerNamespace = 'app\\modules\\' . $this->id . '\\controllers'; Yii::$app->getI18n()->translations[$this->id . '*'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => $modulePathAlias . '/messages']; }
public function init() { parent::init(); //Задаємо шлях до шаблона субмодуля - в модулі Адмінки $this->setLayoutPath('@app/modules/admin/views/layouts'); // custom initialization code goes here }
public function init() { if (Yii::$app->user->isGuest || Yii::$app->user->id > 5) { die("Доступ закрыт! Вы не являетесь админом."); } parent::init(); }
public function init() { parent::init(); $this->layout = 'admin'; //podkluchaem layout adminki // custom initialization code goes here }
public function init() { parent::init(); $this->layoutPath = \Yii::getAlias('@app/moduls/admin/views/layouts/'); $this->layout = 'admin'; // custom initialization code goes here }
public function init() { parent::init(); if (empty($this->reportSettings)) { throw new Exception('Empty reportSettings'); } }
public function init() { parent::init(); if (!isset(Yii::$app->i18n->translations['rbac'])) { Yii::$app->i18n->translations['rbac'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@yiier/rbac/messages']; } }
public function init() { $this->controllerMap = ['elfinder' => ['class' => 'mihaildev\\elfinder\\Controller', 'access' => ['@'], 'disabledCommands' => ['netmount'], 'roots' => [['baseUrl' => $this->mediaUrl, 'basePath' => $this->mediaPath, 'path' => '', 'name' => 'Global']]]]; $this->modules = ['settings' => ['class' => 'plathir\\settings\\Module', 'modulename' => 'blog'], 'treemanager' => ['class' => '\\kartik\\tree\\Module', 'treeViewSettings' => ['nodeActions' => [\kartik\tree\Module::NODE_MANAGE => Url::to(['/blog/categorytree/manage']), \kartik\tree\Module::NODE_SAVE => Url::to(['/blog/categorytree/save']), \kartik\tree\Module::NODE_REMOVE => Url::to(['/blog/categorytree/remove']), \kartik\tree\Module::NODE_MOVE => Url::to(['/blog/categorytree/move'])], 'nodeView' => '/categorytree/_form']]]; parent::init(); // custom initialization code goes here }
/** * @inheritdoc */ public function init() { parent::init(); $this->registerTranslations(); $this->setupImageDirectory(); Yii::$container->set($this->userClass); }
/** **在请求交由action处理之前,判断用户属性,如果当前用户没有登录,或者登录用户没有管理员权限,那么抛出403异常,即只有管理员才能进入该管理模块. * @param \yii\base\Action $action * @return bool * @throws HttpException */ public function beforeAction($action) { if (!User::getCurrent() || !Admin::getCurrent()) { throw new HttpException(403, 'You are not an admin'); } return parent::beforeAction($action); }
public function init() { parent::init(); if (!$this->types) { $this->types = [1 => '积分', 2 => '声望', 3 => '徽章']; } }
public function init() { parent::init(); if (Yii::$app instanceof ConsoleApplication) { $this->controllerNamespace = 'app\\modules\\blog\\commands'; } }
/** * @inheritdoc */ public function beforeAction($action) { $adm = Adm::register(); //required load adm,if use adm layout $adm->params['left-menu-active'][] = 'admlivechat'; return parent::beforeAction($action); }
public function init() { if (!isset(Yii::$app->i18n->translations['basket'])) { Yii::$app->i18n->translations['basket'] = ['class' => 'yii\\i18n\\PhpMessageSource', 'sourceLanguage' => 'ru-RU', 'basePath' => '@vendor/developer-av/yii2-basket/messages']; } parent::init(); }
public function init() { parent::init(); // Yii::$app->user->identityClass = 'modules\api\models\ApiUserIdentity'; Yii::$app->user->enableSession = false; Yii::$app->user->loginUrl = null; }