preserveKeys) { $models = $dataProvider->getModels(); } else { $models = array_values($dataProvider->getModels()); } $models = $this->serializeModels($models); $pagination = $dataProvider->getPagination(); //因为tcp传输,所以不用获取分页链接 // if (($pagination = $dataProvider->getPagination()) !== false) { // $this->addPaginationHeaders($pagination); // } // if ($this->request->getIsHead()) { // return null; // } else if ($this->collectionEnvelope === null) { return $models; } $result = [ $this->collectionEnvelope => $models, ]; if ($pagination !== false) { return array_merge($result, $this->serializePagination($pagination)); } return $result; } /** * Serializes a pagination into an array. * @param Pagination $pagination * @return array the array representation of the pagination * @see addPaginationHeaders() */ protected function serializePagination($pagination) { return [ // $this->linksEnvelope => Link::serialize($pagination->getLinks(true)), $this->metaEnvelope => [ 'totalCount' => $pagination->totalCount, 'pageCount' => $pagination->getPageCount(), 'currentPage' => $pagination->getPage() + 1, 'perPage' => $pagination->getPageSize(), ], ]; } /** * Serializes a model object. * @param Arrayable $model * @return array the array representation of the model */ protected function serializeModel($model) { // if ($this->request->getIsHead()) { // return null; // } // list($fields, $expand) = $this->getRequestedFields(); $fields = [];$expand=[]; return $model->toArray($fields, $expand); } }