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


PHP ActiveController::beforeAction方法代碼示例

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


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

示例1: beforeAction

 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     Yii::$app->response->format = Response::FORMAT_JSON;
     return true;
 }
開發者ID:joorloohuis,項目名稱:bat-web-frontend,代碼行數:8,代碼來源:JobController.php

示例2: beforeAction

 /**
  * This method is used to valide the user's authority with token.
  * This method is invoked right before an action is executed.
  *
  * The method will trigger the [[EVENT_BEFORE_ACTION]] event. The return value of the method
  * will determine whether the action should continue to run.
  *
  * If you override this method, your code should look like the following:
  *
  * ```php
  * public function beforeAction($action)
  * {
  *     if (parent::beforeAction($action)) {
  *         // your custom code here
  *         return true;  // or false if needed
  *     } else {
  *         return false;
  *     }
  * }
  * ```
  *
  * @param Action $action the action to be executed.
  * @return boolean whether the action should continue to run.
  * @author Harry Sun
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $this->attachBehavior('ControllerBehavior', new ControllerBehavior());
         $token = $this->getAccessToken();
         return $this->checkAuth($this->module, $token);
     }
     throw new HttpException(400, "Fail to resolve the action.");
 }
開發者ID:timelessmemory,項目名稱:uhkklp,代碼行數:34,代碼來源:RestController.php

示例3: beforeAction

 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     return $this->encryptDataBeforeAction();
     // your custom code here
     //return true; // or false to not run the action
 }
開發者ID:Olwn,項目名稱:pm25,代碼行數:9,代碼來源:UserTakeinController.php

示例4: beforeAction

 /**
  * @param \yii\base\Action $action
  * @return bool
  * @throws \yii\web\BadRequestHttpException
  */
 public function beforeAction($action)
 {
     if (parent::beforeAction($action)) {
         $this->request = Yii::$app->request;
         Yii::info('請求地址:' . $this->request->absoluteUrl, 'request');
         Yii::info('請求數據:' . $this->request->rawBody, 'request');
         return true;
     } else {
         return false;
     }
 }
開發者ID:forecho,項目名稱:bese-restful,代碼行數:16,代碼來源:ActiveController.php

示例5: beforeAction

 public function beforeAction($action)
 {
     if (!parent::beforeAction($action)) {
         return false;
     }
     foreach ($this->validateNested as $action) {
         if ($this->action->id === $action) {
             if ($this->indexDataProvider()->getTotalCount() === 0) {
                 throw new NotFoundHttpException("Object not found");
             }
         }
     }
     return true;
 }
開發者ID:shaan360,項目名稱:Yii2_foundation-apps,代碼行數:14,代碼來源:NestedActiveController.php

示例6: beforeAction

 /**
  * @param \yii\base\Action $event
  * @return bool
  */
 public function beforeAction($event)
 {
     try {
         $valid = parent::beforeAction($event);
         if ($valid && in_array($event->id, ['create']) && !preg_match('~' . Response::FORMAT_JSON . '~', Yii::$app->request->contentType)) {
             $this->showError(406, "Content type must be '" . Response::FORMAT_JSON . "'");
             return false;
         }
         if ($valid && in_array($event->id, ['update', 'delete'])) {
             $this->showError(403, "Access denied to action '" . $event->id . "'");
             return false;
         }
         return $valid;
     } catch (Exception $e) {
         $this->showError(405, $e->getMessage());
         return false;
     }
 }
開發者ID:an2riy,項目名稱:device.info,代碼行數:22,代碼來源:StatsController.php

示例7: beforeAction

 public function beforeAction($action)
 {
     $request = Yii::$app->request;
     $paras = $request->isPost ? $request->post() : $request->get();
     if (!isset($paras['access_token'])) {
         Yii::$app->getResponse()->content = array('token_status' => -1, 'last_login' => '');
         return parent::beforeAction($action);
     }
     $user1 = \app\models\User::find()->where(['access_token' => $paras['access_token']])->one();
     $user2 = \app\models\User::find()->where(['old_token' => $paras['access_token']])->one();
     $token_status = 0;
     $last_login = null;
     if (!is_null($user1)) {
         $last_login = $user1->last_login;
         $token_status = 1;
     }
     if (!is_null($user2)) {
         $last_login = $user2->last_login;
         $token_status = 2;
     }
     Yii::$app->getResponse()->content = array('token_status' => $token_status, 'last_login' => $last_login);
     //Yii::$app->getResponse()->send();
     return parent::beforeAction($action);
 }
開發者ID:Olwn,項目名稱:pm25,代碼行數:24,代碼來源:CheckTokenController.php

示例8: beforeAction

 /**
  * @inheritdoc
  */
 public function beforeAction($action)
 {
     /** @var ContentNegotiator $negotiator */
     if (($negotiator = $this->getBehavior('contentNegotiator')) !== null) {
         $negotiator->negotiate();
         if (Yii::$app->response->format !== Response::FORMAT_HTML) {
             $this->enableCsrfValidation = false;
         }
     }
     return parent::beforeAction($action);
 }
開發者ID:netis-pl,項目名稱:yii2-crud,代碼行數:14,代碼來源:ActiveController.php

示例9: beforeAction

 public function beforeAction($action)
 {
     $this->enableCsrfValidation = false;
     return parent::beforeAction($action);
 }
開發者ID:C12D,項目名稱:advancedapi,代碼行數:5,代碼來源:Gps_customerController.php

示例10: beforeAction

 public function beforeAction($event)
 {
     return parent::beforeAction($event);
 }
開發者ID:apmauj,項目名稱:1f8bf10ab74d6f5ca69f7c07b7ee1c38,代碼行數:4,代碼來源:BaseActiveController.php

示例11: beforeAction

 public function beforeAction($action)
 {
     $this->page_size = Yii::$app->request->get('per-page') ? Yii::$app->request->get('per-page') : $this->page_size;
     if ($action->id == 'create' || $action->id == 'update') {
         if ($this->auto_filter_user && $this->user_identifier_column) {
             $params = Yii::$app->getRequest()->getBodyParams();
             $params[$this->user_identifier_column] = strval(Yii::$app->user->id);
             Yii::$app->getRequest()->setBodyParams($params);
         }
     }
     return $this->handleBeforeActionEvent($action) && parent::beforeAction($action);
 }
開發者ID:dawei101,項目名稱:plants,代碼行數:12,代碼來源:ApiController.php


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