search(Yii::$app->request->queryParams); $reports_array = ArrayHelper::toArray($dataProvider->getModels(), [ 'common\models\Reports' => [ 'id', 'created_at', 'difficulties', 'tomorrow', 'user_card_id', 'today' => function ($report) { return ArrayHelper::toArray($report->task, [ 'common\models\ReportsTask' => [ 'hours_spent', 'task' ], ]); } ], ]); $response = Yii::$app->response; $response->format = Response::FORMAT_JSON; $response->getHeaders()->set('Content-Type', 'application/json; charset=utf-8'); $response->content = json_encode(array_merge( ['reports' => $reports_array], ['month' => (array)new Month($year.'-'.$month.'-01')]) ); return $response; } }