当前位置: 首页>>代码示例>>PHP>>正文


PHP Module::beforeAction方法代码示例

本文整理汇总了PHP中yii\base\Module::beforeAction方法的典型用法代码示例。如果您正苦于以下问题:PHP Module::beforeAction方法的具体用法?PHP Module::beforeAction怎么用?PHP Module::beforeAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\base\Module的用法示例。


在下文中一共展示了Module::beforeAction方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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;
     }
 }
开发者ID:Sywooch,项目名称:TailorPlace,代码行数:35,代码来源:Cabinet.php

示例2: beforeAction

 public function beforeAction($action)
 {
     if ($this->beforeAction !== null && !call_user_func($this->beforeAction, $action)) {
         return false;
     }
     return parent::beforeAction($action);
 }
开发者ID:MikleUA,项目名称:yii2-rbac-plus,代码行数:7,代码来源:Module.php

示例3: beforeAction

 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     return true;
 }
开发者ID:gbksoft,项目名称:yii2-tokens,代码行数:10,代码来源:Module.php

示例4: beforeAction

 public function beforeAction($action)
 {
     $action->controller->layout = '//doctor';
     $action->controller->view->registerJsFile('/jsLib/prj/doctor.js', ['position' => \yii\web\View::POS_END]);
     return parent::beforeAction($action);
     // TODO: Change the autogenerated stub
 }
开发者ID:kutsanov,项目名称:med,代码行数:7,代码来源:Module.php

示例5: beforeAction

 /**
  **在请求交由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);
 }
开发者ID:aixiaobenaixiaoben,项目名称:find,代码行数:13,代码来源:Module.php

示例6: beforeAction

 public function beforeAction($action)
 {
     parent::beforeAction($action);
     if (Yii::$app->user->isGuest || Yii::$app->user->status == 'user') {
         Yii::$app->getResponse()->redirect(Yii::$app->user->loginUrl);
     }
 }
开发者ID:gryshkoevgeniy,项目名称:booksfromyii,代码行数:7,代码来源:AdminModule.php

示例7: beforeAction

 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         return $this->checkAccess($action);
     }
     return false;
 }
开发者ID:rkit,项目名称:bootstrap-yii2,代码行数:7,代码来源:Module.php

示例8: beforeAction

 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         //update users online information
         $this->updateOnlineStatus($action);
         // register visit by webspider
         if (isset($_SERVER['HTTP_USER_AGENT'])) {
             $spider = YBoardSpider::find()->where(['user_agent' => $_SERVER['HTTP_USER_AGENT']])->one();
         } else {
             $spider = null;
         }
         if ($spider != null) {
             $spider->setScenario('visit');
             $spider->hits++;
             $spider->last_visit = null;
             $spider->save();
         }
         //menu fixed for Views
         $approvals1 = YBoardPost::find()->unapprovedScope()->count();
         $approvals2 = YBoardTopic::find()->andWhere(['approved' => 0])->count();
         $reports = YBoardMessage::find()->reportScope()->unreadScope()->count();
         $this->params['foroMenu'] = [['label' => Yii::t('app', 'Members'), 'url' => ['member/index']], ['label' => Yii::t('app', 'Pending') . ' (' . ($approvals1 + $approvals2) . ')', 'url' => ['moderator/approve'], 'visible' => Yii::$app->user->can('moderator')], ['label' => Yii::t('app', 'Reported') . ' (' . $reports . ')', 'url' => ['moderator/reported'], 'visible' => Yii::$app->user->can('moderator')]];
         return true;
     } else {
         return false;
     }
 }
开发者ID:dextercool,项目名称:yii2-yiiboard,代码行数:27,代码来源:YBoard.php

示例9: runAction

 /**
  * Runs an action within this controller with the specified action ID and parameters.
  * If the action ID is empty, the method will use [[defaultAction]].
  * @param string $id the ID of the action to be executed.
  * @param array $params the parameters (name-value pairs) to be passed to the action.
  * @return mixed the result of the action.
  * @throws InvalidRouteException if the requested action ID cannot be resolved into an action successfully.
  * @see createAction()
  */
 public function runAction($id, $params = [])
 {
     $action = $this->createAction($id);
     if ($action !== null) {
         Yii::trace("Route to run: " . $action->getUniqueId(), __METHOD__);
         if (Yii::$app->requestedAction === null) {
             Yii::$app->requestedAction = $action;
         }
         $oldAction = $this->action;
         $this->action = $action;
         $result = null;
         $event = new ActionEvent($action);
         Yii::$app->trigger(Application::EVENT_BEFORE_ACTION, $event);
         if ($event->isValid && $this->module->beforeAction($action) && $this->beforeAction($action)) {
             $result = $action->runWithParams($params);
             $this->afterAction($action, $result);
             $this->module->afterAction($action, $result);
             $event = new ActionEvent($action);
             $event->result =& $result;
             Yii::$app->trigger(Application::EVENT_AFTER_ACTION, $event);
         }
         $this->action = $oldAction;
         return $result;
     } else {
         throw new InvalidRouteException('Unable to resolve the request: ' . $this->getUniqueId() . '/' . $id);
     }
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:36,代码来源:Controller.php

示例10: beforeAction

 public function beforeAction($action)
 {
     if ($this->getIsInstalled() == true) {
         \Yii::$app->getResponse()->redirect("admin.php");
         return false;
     }
     return parent::beforeAction($action);
 }
开发者ID:yii2ApplicationCollect,项目名称:hasscms-app,代码行数:8,代码来源:Module.php

示例11: beforeAction

 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     $adm = Adm::register();
     if (!parent::beforeAction($action) || !$adm->user->can('AdmRoot')) {
         return false;
     }
     return true;
 }
开发者ID:pavlinter,项目名称:yii2-adm-params,代码行数:11,代码来源:Module.php

示例12: beforeAction

 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     $this->resetGlobalSettings();
     return true;
 }
开发者ID:dizews,项目名称:yii2-qunit,代码行数:11,代码来源:Module.php

示例13: beforeAction

 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if ($this->checkAccess()) {
         return parent::beforeAction($action);
     } else {
         throw new ForbiddenHttpException('You are not allowed to access this page.');
     }
 }
开发者ID:indicalabs,项目名称:yii2-plupload,代码行数:11,代码来源:Module.php

示例14: beforeAction

 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     // Block installer, when it's marked as installed
     if (Yii::$app->params['installed']) {
         throw new HttpException(500, 'Application is already installed!');
     }
     Yii::$app->controller->enableCsrfValidation = false;
     return parent::beforeAction($action);
 }
开发者ID:artkost,项目名称:yii2-starter-kit,代码行数:12,代码来源:Module.php

示例15: beforeAction

 public function beforeAction($action)
 {
     $aId = $action->id;
     if ($aId == "register" && !$this->enableRegister) {
         throw new \yii\web\NotFoundHttpException("Page not found");
     } else {
         return parent::beforeAction($action);
     }
 }
开发者ID:johnitvn,项目名称:yii2-user-plus,代码行数:9,代码来源:Module.php


注:本文中的yii\base\Module::beforeAction方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。