user->enableSession = false; } public function behaviors() { $behaviors = parent::behaviors(); $behaviors['authenticator'] = [ 'class' => CompositeAuth::className(), 'authMethods' => [ // HttpBasicAuth::className(), // HttpBearerAuth::className(), QueryParamAuth::className(), ], ]; // 数据返回类型设置 //$behaviors['contentNegotiator']['formats']['application/json'] = 'json'; //$behaviors['contentNegotiator']['formats']['application/xml'] = 'json'; return $behaviors; } public function beforeAction($action) { parent::beforeAction($action); $this->post = yii::$app->request->post(); $this->get = yii::$app->request->get(); $this->user = yii::$app->user->identity; $this->userId = Yii::$app->user->id; return $action; } }