/** * Adds HTTP headers about the pagination to the response. * @param Pagination $pagination */ protected function addPaginationHeaders($pagination) { $links = []; foreach ($pagination->getLinks(true) as $rel => $url) { $links[] = "<{$url}>; rel={$rel}"; } $this->response->getHeaders()->set($this->totalCountHeader, $pagination->totalCount)->set($this->pageCountHeader, $pagination->getPageCount())->set($this->currentPageHeader, $pagination->getPage() + 1)->set($this->perPageHeader, $pagination->pageSize)->set('Link', implode(', ', $links)); }
/** * Sets the pagination for this data provider. * * @param array|Pagination|boolean $value the pagination to be used by this data provider. * This can be one of the following: * * - a configuration array for creating the pagination object. The "class" element defaults * to 'Leaps\Data\Pagination' * - an instance of [[Pagination]] or its subclass * - false, if pagination needs to be disabled. * * @throws InvalidParamException */ public function setPagination($value) { if (is_array($value)) { $config = ['className' => Pagination::className()]; if ($this->id !== null) { $config['pageParam'] = $this->id . '-page'; $config['pageSizeParam'] = $this->id . '-per-page'; } $this->_pagination = Leaps::createObject(array_merge($config, $value)); } elseif ($value instanceof Pagination || $value === false) { $this->_pagination = $value; } else { throw new InvalidParamException('Only Pagination instance, configuration array or false is allowed.'); } }