Skip to content

Instantly share code, notes, and snippets.

@wisaruthk
Created September 29, 2015 08:36
Show Gist options
  • Save wisaruthk/01bdcc082699010d5fec to your computer and use it in GitHub Desktop.
Save wisaruthk/01bdcc082699010d5fec to your computer and use it in GitHub Desktop.
Yii2 custom json response
'response'=>[
'format' => yii\web\Response::FORMAT_JSON,
'class' => 'yii\web\Response',
'on beforeSend' => function ($event) {
$response = $event->sender;
//var_dump($response);
if ($response->data !== null) {
$response->data = [
'success' => $response->getIsSuccessful(),
'statusCode'=> $response->getStatusCOde(),
'data' => $response->data,
];
$response->statusCode = 200;
}
},
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment