當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ActionFilter::beforeAction方法代碼示例

本文整理匯總了PHP中yii\base\ActionFilter::beforeAction方法的典型用法代碼示例。如果您正苦於以下問題:PHP ActionFilter::beforeAction方法的具體用法?PHP ActionFilter::beforeAction怎麽用?PHP ActionFilter::beforeAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\base\ActionFilter的用法示例。


在下文中一共展示了ActionFilter::beforeAction方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: beforeAction

 public function beforeAction($action)
 {
     if ($this->getIsAjax()) {
         $this->ajaxMode = true;
     }
     return parent::beforeAction($action);
 }
開發者ID:vsguts,項目名稱:crm,代碼行數:7,代碼來源:AjaxFilter.php

示例2: beforeAction

 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (Yii::$app->getRequest()->getIsAjax()) {
         return parent::beforeAction($action);
     }
     throw new BadRequestHttpException('Bad Request. This url cannot handle a non-ajax request.');
 }
開發者ID:ivan-chkv,項目名稱:yii2-boost,代碼行數:10,代碼來源:AjaxFilter.php

示例3: beforeAction

 public function beforeAction($action)
 {
     if (Yii::$app->user->id != 1) {
         $action->controller->redirect('/index.php?r=fund/currency/index');
     }
     return parent::beforeAction($action);
 }
開發者ID:jh27408079,項目名稱:magenet,代碼行數:7,代碼來源:OnlyMyself.php

示例4: beforeAction

 public function beforeAction($action)
 {
     if ($this->user['role'] >= Users::ROLE_OPERATION) {
         return parent::beforeAction($action);
     }
     throw new Exception("沒有訪問權限");
 }
開發者ID:krissss,項目名稱:YunDou-advanced,代碼行數:7,代碼來源:OperationFilter.php

示例5: beforeAction

 public function beforeAction($action)
 {
     if (!isset($_SESSION['user'])) {
         Yii::$app->controller->redirect(Url::base() . '/index.php?r=user/login');
     }
     return parent::beforeAction($action);
 }
開發者ID:lawguangwei,項目名稱:webDB,代碼行數:7,代碼來源:LoginFilter.php

示例6: beforeAction

 public function beforeAction($action)
 {
     if (\Yii::$app->request->isAjax) {
         return parent::beforeAction($action);
     }
     throw new BadRequestHttpException();
 }
開發者ID:heartshare,項目名稱:yii2-chat,代碼行數:7,代碼來源:AjaxFilter.php

示例7: beforeAction

 /**
  * @param \yii\base\Action $action
  *
  * @return bool
  * @throws InvalidParamException
  */
 public function beforeAction($action)
 {
     $session = \Yii::$app->session;
     $request = \Yii::$app->request;
     if ($request->post('web_id')) {
         $id = $request->post('web_id');
         $session->set('web_id', $id);
     } elseif ($session->get('web_id')) {
         $web = WebRecord::findOne($session->get('web_id'));
         if ($web) {
             $id = $session->get('web_id');
         } else {
             $id = WebRecord::getMainWebId();
             $session->set('web_id', $id);
         }
     } else {
         $id = WebRecord::getMainWebId();
         $session->set('web_id', $id);
     }
     $session->close();
     /** @var $controller MenuController */
     $controller = $this->owner;
     $controller->setWeb($id);
     return parent::beforeAction($action);
 }
開發者ID:czechcamus,項目名稱:dasport,代碼行數:31,代碼來源:WebFilter.php

示例8: beforeAction

 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $user = $this->getUser();
         if (in_array($action->getUniqueId(), $this->allowedActions)) {
             return true;
         } elseif ($user->isGuest) {
             Yii::$app->response->redirect(['/radiata/login'])->send();
             return false;
         } elseif (in_array($action->getUniqueId(), $this->allowedActionsLoggedIn)) {
             return true;
         }
         $userGroups = Yii::$app->authManager->getAssignments($user->id);
         if (self::checkFullAccess()) {
             return true;
         } elseif (isset($userGroups['manager'])) {
             if ($action->controller->id == 'radiata' && isset($userGroups['manager'])) {
                 return true;
             } elseif (defined(get_class($action->controller) . '::BACKEND_PERMISSION') && $user->can(constant(get_class($action->controller) . '::BACKEND_PERMISSION'))) {
                 return true;
             } elseif (!defined(get_class($action->controller) . '::BACKEND_PERMISSION') && defined(get_class($action->controller->module) . '::BACKEND_PERMISSION') && $user->can(constant(get_class($action->controller->module) . '::BACKEND_PERMISSION'))) {
                 return true;
             } else {
                 throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
             }
         } else {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
     return false;
 }
開發者ID:radiata-cms,項目名稱:radiata,代碼行數:34,代碼來源:BackendAccessControl.php

示例9: beforeAction

 /**
  * @param \yii\base\Action $action
  *
  * @return bool
  * @throws InvalidParamException
  */
 public function beforeAction($action)
 {
     $session = \Yii::$app->session;
     $request = \Yii::$app->request;
     if ($request->post('web_id')) {
         $session->set('web_id', $request->post('web_id'));
         $id = MenuRecord::getMainMenuId();
         $session->set('menu_id', $id);
     } else {
         if ($request->post('menu_id')) {
             $id = $request->post('menu_id');
             $session->set('menu_id', $id);
         } elseif ($session->get('menu_id')) {
             $menu = MenuRecord::findOne($session->get('menu_id'));
             if ($menu) {
                 $id = $session->get('menu_id');
             } else {
                 $id = MenuRecord::getMainMenuId();
                 $session->set('menu_id', $id);
             }
         } else {
             $id = MenuRecord::getMainMenuId();
             $session->set('menu_id', $id);
         }
     }
     $session->close();
     /* @var $controller \backend\controllers\MenuItemController */
     $controller = $this->owner;
     $controller->setMenu($id);
     return parent::beforeAction($action);
 }
開發者ID:czechcamus,項目名稱:dasport,代碼行數:37,代碼來源:MenuFilter.php

示例10: beforeAction

 /**
  * @param Action $action
  * @return bool
  * @throws ForbiddenHttpException
  * @throws \yii\base\InvalidConfigException
  */
 public function beforeAction($action)
 {
     $action_name = $action->id;
     list($public_actions, $actions_scopes) = $this->analyzeAccessRules($action_name);
     if (in_array($action_name, $public_actions)) {
         //action is public
         return true;
     }
     // else, if not public, add additional auth filters
     if (Yii::$app->hasModule('oauth2')) {
         /** @var \filsh\yii2\oauth2server\Module $oauth_module */
         $oauth_module = Yii::$app->getModule('oauth2');
         $query_param_auth = ['class' => QueryParamAuth::className()];
         if (!empty($oauth_module->options['token_param_name'])) {
             $query_param_auth['tokenParam'] = $oauth_module->options['token_param_name'];
         }
         $auth_behavior = $this->owner->getBehavior('authenticator');
         $auth_behavior->authMethods = [$query_param_auth, ['class' => HttpBearerAuth::className()]];
         $scopes = isset($actions_scopes[$action_name]) ? $actions_scopes[$action_name] : '';
         if (is_array($scopes)) {
             $scopes = implode(' ', $scopes);
         }
         $oauthServer = $oauth_module->getServer();
         $oauthRequest = $oauth_module->getRequest();
         $oauthResponse = $oauth_module->getResponse();
         if (!$oauthServer->verifyResourceRequest($oauthRequest, $oauthResponse, $scopes)) {
             throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
         }
     }
     return parent::beforeAction($action);
 }
開發者ID:1215048375,項目名稱:yii2-oauth2-rest-template,代碼行數:37,代碼來源:OAuth2AccessFilter.php

示例11: beforeAction

 public function beforeAction($action)
 {
     $session = Yii::$app->session;
     $user = $session->get('user');
     if (!TestLibrary::checkIsExist($user)) {
         $url = Url::to(['site/test-library-not-found']);
         header("Location:{$url}");
     }
     $practiceRecordFlag = $session->getFlash('practiceRecordFlag');
     if ($practiceRecordFlag) {
         //支付方案如果已經生成直接顯示過去
         return parent::beforeAction($action);
     }
     $practiceRecord = PracticeRecord::findByUser($user['userId']);
     if (!$practiceRecord) {
         //如果沒有練習權
         //獲取在線練習支付方案
         /** @var $scheme \common\models\Scheme */
         $schemes = Scheme::findPracticeScheme();
         $session->setFlash('practice-schemes', $schemes);
         //存入session,在練習首頁使用
         $session->setFlash('practiceRecordFlag', true);
         //支付方案生成的標誌
         $url = Url::to(['practice/index', true]);
         header("Location:{$url}");
         return false;
     }
     return parent::beforeAction($action);
 }
開發者ID:krissss,項目名稱:YunDou-advanced,代碼行數:29,代碼來源:PracticeRecordFilter.php

示例12: beforeAction

 public function beforeAction($action)
 {
     if (in_array(Yii::$app->controller->action->id, $this->only)) {
         Yii::$app->controller->enableCsrfValidation = false;
     }
     return parent::beforeAction($action);
 }
開發者ID:kissarat,項目名稱:yii2-template,代碼行數:7,代碼來源:NoTokenValidation.php

示例13: beforeAction

 public function beforeAction($action)
 {
     if (!in_array($this->getClientIp(), Yii::$app->params['terminalAllowedIps'])) {
         throw new ForbiddenHttpException(Yii::t('yii', 'You are not allowed to perform this action.'));
     }
     return parent::beforeAction($action);
 }
開發者ID:nthrnth,項目名稱:catering-terminal,代碼行數:7,代碼來源:IpAccessFilter.php

示例14: beforeAction

 public function beforeAction($action)
 {
     if (Yii::$app->request->isAjax) {
         return parent::beforeAction($action);
     }
     return $action->controller->redirect(['index']);
 }
開發者ID:nthrnth,項目名稱:catering-terminal,代碼行數:7,代碼來源:AjaxOnlyFilter.php

示例15: beforeAction

 public function beforeAction($action)
 {
     if (Yii::$app->user->identity->changePasswordRequired() || Yii::$app->user->identity->temp_pswd_flag) {
         Yii::$app->getSession()->setFlash('success', Yii::t('app', 'You must change your password before you can proceed.'));
         Yii::$app->controller->redirect(['/admin/sys-user/change-my-password']);
     }
     return parent::beforeAction($action);
 }
開發者ID:reuhtte,項目名稱:yii2-admin,代碼行數:8,代碼來源:ChangePasswordFilter.php


注:本文中的yii\base\ActionFilter::beforeAction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。