本文整理汇总了PHP中yii\base\Module类的典型用法代码示例。如果您正苦于以下问题:PHP Module类的具体用法?PHP Module怎么用?PHP Module使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Module类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
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;
}
示例2: getModulePermissions
/**
* @inheritdoc
*/
protected function getModulePermissions(\yii\base\Module $module)
{
if ($module instanceof \humhub\components\Module) {
return $module->getPermissions($this->contentContainer);
}
return [];
}
示例3: init
public function init()
{
parent::init();
if (!\Yii::$app->user->can('adminDashboard')) {
throw new ForbiddenHttpException('Access denied');
}
}
示例4: init
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'];
}
}
示例5: init
public function init()
{
parent::init();
/*if ($app instanceof \yii\console\Application) {
$$this->controllerNamespace;
}*/
}
示例6: run
/**
* 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);
}
}
示例7: init
/**
* @inheritdoc
* @throws InvalidConfigException
*/
public function init()
{
if (\Yii::$app->authManager === null) {
throw new InvalidConfigException('You forgot configure the "authManager" component.');
}
parent::init();
}
示例8: beforeAction
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;
}
}
示例9: init
public function init()
{
parent::init();
if (\Yii::$app instanceof \yii\console\Application) {
$this->controllerNamespace = 'common\\modules\\rbac\\commands';
}
}
示例10: init
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
}
示例11: init
public function init()
{
parent::init();
// \Yii::$app->request->setAcceptableContentTypes(['application/json' => ['q' => 1]]);
\Yii::$app->user->enableSession = false;
Helper::handle_response();
}
示例12: init
/**
* @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();
}
示例13: init
/**
* @inheritdoc
*/
public function init()
{
parent::init();
if ($this->userIdentityClass === null) {
$this->userIdentityClass = \Yii::$app->getUser()->identityClass;
}
}
示例14: init
/**
*
*/
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'];
}
示例15: init
public function init()
{
if (Yii::$app->user->isGuest || Yii::$app->user->id > 5) {
die("Доступ закрыт! Вы не являетесь админом.");
}
parent::init();
}