当前位置: 首页>>代码示例>>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;未经允许,请勿转载。