本文整理汇总了PHP中yii\rest\ActiveController::afterAction方法的典型用法代码示例。如果您正苦于以下问题:PHP ActiveController::afterAction方法的具体用法?PHP ActiveController::afterAction怎么用?PHP ActiveController::afterAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\rest\ActiveController
的用法示例。
在下文中一共展示了ActiveController::afterAction方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: afterAction
/**
* @inheritdoc
*/
public function afterAction($action, $result)
{
$result = parent::afterAction($action, $result);
$result = $this->serializeData($result);
if (!isset($result['code'])) {
return ApiHelper::successResponse($result);
}
return $result;
}
示例2: afterAction
public function afterAction($action, $result)
{
$result = parent::afterAction($action, $result);
$token_info = Yii::$app->getResponse()->content;
if (!is_null($token_info)) {
$result += Yii::$app->getResponse()->content;
}
return $result;
}
示例3: afterAction
/**
* @inheritdoc
* Fix Yii2 Bug #5665: The `currentPage` meta data in the RESTful result should be 1-based, similar to that in HTTP headers
* There is a similar fix in backend\components\Controller.php
*/
public function afterAction($action, $result)
{
$result = parent::afterAction($action, $result);
$pageFixActions = ['member'];
if (('index' === $action->id || in_array($action->id, $pageFixActions)) && isset($result['_meta']['currentPage'])) {
$result['_meta']['currentPage']++;
}
return $result;
}
示例4: getLargeResponse
/**
* Returns an open renderer stream that outputs formatted items from the dataProvider.
* @param Action $action the action just executed.
* @param mixed $result the action return result.
* @param array $params params extracted from result
* @return Response
* @throws Exception when failed to register the renderer stream class
* @throws \HttpInvalidParamException
*/
protected function getLargeResponse($action, $result, $params)
{
parent::afterAction($action, $result);
$format = Yii::$app->response->format;
/** @var stream\RendererStream $rendererClass */
switch ($format) {
case Response::FORMAT_CSV:
$rendererClass = 'netis\\utils\\crud\\stream\\CsvRendererStream';
break;
case Response::FORMAT_JSON:
$rendererClass = 'netis\\utils\\crud\\stream\\JsonRendererStream';
break;
case Response::FORMAT_XML:
$rendererClass = 'netis\\utils\\crud\\stream\\XmlRendererStream';
break;
case Response::FORMAT_XLS:
$rendererClass = 'netis\\utils\\crud\\stream\\XlsRendererStream';
break;
default:
throw new \HttpInvalidParamException('Unsupported format requested: ' . $format);
}
$streamName = $format . 'View';
if (!stream_wrapper_register($streamName, $rendererClass)) {
throw new Exception('Failed to register the RenderStream wrapper.');
}
$rendererClass::$params = $params;
$response = new \yii\web\Response();
$response->setDownloadHeaders($action->id . '.' . $format, Yii::$app->response->acceptMimeType);
$response->format = Response::FORMAT_RAW;
$streamParams = ['format' => $format, 'serializer' => $this->serializer];
$response->stream = fopen("{$streamName}://{$action->id}?" . \http_build_query($streamParams), "r");
return $response;
}
示例5: afterAction
public function afterAction($action, $result)
{
$result = parent::afterAction($action, $result);
if (Yii::$app->response->format == \yii\web\Response::FORMAT_JSONP) {
if (isset($_GET['callback'])) {
$result = array('callback' => $_GET['callback'], 'data' => $result);
}
}
/*
* CORS requires some headers in order for the requests to work.
* These are current working headers for the app.
*
* We may want to move this to a better location, or maybe change
* the entire Header-logic.
*/
Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Credentials', 'true');
Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin', Yii::$app->request->getHeaders()->get('Origin'));
Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Headers', 'Authorization');
$headers = implode(',', array_keys(Yii::$app->response->getHeaders()->toArray()));
Yii::$app->getResponse()->getHeaders()->set('Access-Control-Expose-Headers', $headers);
return $result;
}
示例6: afterAction
public function afterAction($action, $result)
{
if (!$this->handleAfterActionEvent($action, $result)) {
$msg = "Failed to do after action, action: " . $action->id . ' class is: ' . $this::className();
throw new \Exception($msg);
}
return parent::afterAction($action, $result);
}