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


PHP ActiveController::behaviors方法代碼示例

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


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

示例1: behaviors

 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['rateLimiter'] = ['class' => RateLimiter::className(), 'enableRateLimitHeaders' => false];
     $behaviors['contentNegotiator'] = ['class' => ContentNegotiator::className(), 'formats' => ['application/json' => Response::FORMAT_JSON]];
     return $behaviors;
 }
開發者ID:pylypen,項目名稱:api-side,代碼行數:10,代碼來源:UserController.php

示例2: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     /*
     // test with basic auth which can be set in params
     $behaviors['authenticator'] = [
     'class' => HttpBasicAuth::className(),
     'auth'  => function ($username, $password) {
         if ($username==\Yii::$app->params['HttpBasicAuth']['username'] && $password==\Yii::$app->params['HttpBasicAuth']['password']) {
             return new User();
         } else {
             return null;
         }
     }];
     */
     $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'authMethods' => [HttpBasicAuth::className(), QueryParamAuth::className()]];
     /*
     //set response header to application/json only
     $behaviors['contentNegotiator'] = [
             'class' => ContentNegotiator::className(),
             'formats' => [
                 'application/json' => Response::FORMAT_JSON,
     //            'application/xml' => Response::FORMAT_XML,
             ],
     ];
     */
     return $behaviors;
 }
開發者ID:EuresTools,項目名稱:eVote-web,代碼行數:28,代碼來源:BaseRestController.php

示例3: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => HttpBasicAuth::className()];
     /*
      * The W3 spec for CORS preflight requests clearly states that user credentials should be excluded. 
      * There is a bug in Chrome and WebKit where OPTIONS requests returning a status of 401 still send 
      * the subsequent request.
      *
      * Firefox has a related bug filed that ends with a link to the W3 public webapps mailing list asking 
      * for the CORS spec to be changed to allow authentication headers to be sent on the OPTIONS request 
      * at the benefit of IIS users. Basically, they are waiting for those servers to be obsoleted.
      * 
      * How can I get the OPTIONS request to send and respond consistently?
      * 
      * Simply have the server (API in this example) respond to OPTIONS requests without requiring authentication. 
      */
     /*$behaviors['access'] = [
           'class' => AccessControl::className(),
           'only' => ['options'],
           'rules' => [
               [
                   'allow' => true,
                   'roles' => '?',
               ],
           ]
       ];*/
     $behaviors['contentNegotiator']['formats']['application/json'] = isset($_GET['callback']) ? \yii\web\Response::FORMAT_JSONP : \yii\web\Response::FORMAT_JSON;
     $behaviors['contentNegotiator']['formats']['application/jsonp'] = \yii\web\Response::FORMAT_JSONP;
     return $behaviors;
 }
開發者ID:RHeSuS-project,項目名稱:POC-service,代碼行數:31,代碼來源:XActiveController.php

示例4: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['verbs'] = ['class' => VerbFilter::className(), 'actions' => ['indexWithQuote' => ['get']]];
     $behaviors['authenticator'] = ['class' => HttpBasicAuth::className()];
     return $behaviors;
 }
開發者ID:soanni,項目名稱:stocks_mvc,代碼行數:7,代碼來源:RatesController.php

示例5: behaviors

 public function behaviors()
 {
     $self = self::className();
     $behaviors = parent::behaviors();
     $behaviors['access'] = ['class' => \app\components\filters\AccessControl::className(), 'rules' => $self::getAccessRules()];
     return $behaviors;
 }
開發者ID:KleinMaximus,項目名稱:pickam,代碼行數:7,代碼來源:ActiveController.php

示例6: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => HttpBearerAuth::className(), 'except' => ['options']];
     $behaviors['corsFilter'] = ['class' => Cors::className()];
     return $behaviors;
 }
開發者ID:kuznetsov0209,項目名稱:mercdev-soccer-server,代碼行數:7,代碼來源:SecureActiveController.php

示例7: behaviors

 /**
  * 行為擴展
  * @return array
  */
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     //        $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_HTML;
     $behaviors['contentNegotiator']['formats'] = ['application/json' => Response::FORMAT_JSON];
     return $behaviors;
 }
開發者ID:xidiao,項目名稱:gxfenxi,代碼行數:11,代碼來源:UserController.php

示例8: behaviors

 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     $behaviors = ArrayHelper::merge(parent::behaviors(), ['authenticator' => ['class' => CompositeAuth::className(), 'authMethods' => [['class' => HttpBearerAuth::className()], ['class' => QueryParamAuth::className(), 'tokenParam' => 'accessToken']]], 'exceptionFilter' => ['class' => ErrorToExceptionFilter::className()], 'corsFilter' => ['class' => \backend\rest\filters\Cors::className(), 'cors' => ['Origin' => ['*'], 'Access-Control-Request-Method' => ['POST', 'PUT', 'OPTIONS', 'PATCH', 'DELETE'], 'Access-Control-Request-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Credentials' => true, 'Access-Control-Max-Age' => 3600, 'Access-Control-Expose-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link'], 'Access-Control-Allow-Headers' => ['X-Pagination-Total-Count', 'X-Pagination-Page-Count', 'X-Pagination-Current-Page', 'X-Pagination-Per-Page', 'Content-Length', 'Content-type', 'Link']]]]);
     if (isset(\Yii::$app->params['httpCacheActive']) and \Yii::$app->params['httpCacheActive']) {
         $params = \Yii::$app->getRequest()->getQueryParams();
         unset($params['accessToken']);
         $behaviors['httpCache'] = ['class' => HttpCache::className(), 'params' => $params, 'lastModified' => function ($action, $params) {
             $q = new \yii\db\Query();
             $class = $this->modelClass;
             if (in_array('updated_at', $class::getTableSchema()->getColumnNames())) {
                 return strtotime($q->from($class::tableName())->max('updated_at'));
             }
             if (in_array('modified', $class::getTableSchema()->getColumnNames())) {
                 return strtotime($q->from($class::tableName())->max('modified'));
             }
             return null;
         }, 'etagSeed' => function (Action $action, $params) {
             $iterator = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($params));
             $keys = array();
             foreach ($iterator as $key => $value) {
                 // Build long key name based on parent keys
                 for ($i = $iterator->getDepth() - 1; $i >= 0; $i--) {
                     $key = $iterator->getSubIterator($i)->key() . '_' . $key;
                     if (!is_array($iterator->getSubIterator($i)->current())) {
                         $value = $iterator->getSubIterator($i)->current() . '_' . $value;
                     }
                 }
                 $keys[] = $key . '-' . $value;
             }
             $uniqueId = implode('-', $keys);
             return $uniqueId;
         }];
     }
     return $behaviors;
 }
開發者ID:portalsway2,項目名稱:APEDevices,代碼行數:38,代碼來源:Controller.php

示例9: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_HTML;
     //        $behaviors['contentNegotiator']['languages'] = [ 'en', 'zh-CN',];
     return $behaviors;
 }
開發者ID:bennybi,項目名稱:yii2-cza-base,代碼行數:7,代碼來源:ModelController.php

示例10: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator']['class'] = QueryParamAuth::className();
     $behaviors['authenticator']['tokenParam'] = 'access_token';
     return $behaviors;
 }
開發者ID:fosker,項目名稱:dbm,代碼行數:7,代碼來源:UserController.php

示例11: behaviors

 /**
  * Some rules in this controller
  * @return Rules behaviors
  */
 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => QueryParamAuth::className(), 'tokenParam' => 'token'];
     unset($behaviors['rateLimiter']);
     return $behaviors;
 }
開發者ID:bolom009,項目名稱:testwork_api,代碼行數:11,代碼來源:UserController.php

示例12: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => HttpBearerAuth::className()];
     $behaviors['contentNegotiator'] = ['class' => ContentNegotiator::className(), 'formats' => ['application/json' => Response::FORMAT_JSON]];
     return $behaviors;
 }
開發者ID:AndriyK,項目名稱:team,代碼行數:7,代碼來源:TeamController.php

示例13: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => HttpBearerAuth::className()];
     $behaviors['access'] = ['class' => AccessControl::className(), 'only' => ['create', 'index', 'update', 'delete'], 'rules' => [['allow' => true, 'actions' => ['create', 'index', 'update', 'delete'], 'roles' => ['ADMIN']]]];
     return $behaviors;
 }
開發者ID:zxvad,項目名稱:PriceCalculationOfCircuitBoards,代碼行數:7,代碼來源:InputparamsController.php

示例14: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'except' => ['login', 'error'], 'authMethods' => [HttpBearerAuth::className()]];
     unset($behaviors['rateLimiter']);
     return $behaviors;
 }
開發者ID:bookin,項目名稱:yii2-rest-example,代碼行數:7,代碼來源:Controller.php

示例15: behaviors

 public function behaviors()
 {
     $behaviors = parent::behaviors();
     //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON; //setting JSON as default reply
     $behaviors['authenticator'] = ['class' => CompositeAuth::className(), 'authMethods' => [HttpBasicAuth::className(), HttpBearerAuth::className(), QueryParamAuth::className()]];
     return $behaviors;
 }
開發者ID:dimichspb,項目名稱:yii2-api-auth,代碼行數:7,代碼來源:CountryController.php


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