getPageSize() public method

By default, this method will try to determine the page size by [[pageSizeParam]] in [[params]]. If the page size cannot be determined this way, [[defaultPageSize]] will be returned.
See also: pageSizeLimit
public getPageSize ( ) : integer
return integer the number of items per page. If it is less than 1, it means the page size is infinite, and thus a single page contains all items.
Esempio n. 1
0
 /**
  * Creates an url for the specified page size.
  * @param \yii\data\Pagination $pagination
  * @param integer $pageSize page size
  * @param boolean $absolute whether to create an absolute URL. Defaults to `false`.
  *
  * @return string the created URL
  */
 public static function createSizeUrl($pagination, $pageSize, $absolute = false)
 {
     if (($params = $pagination->params) === null) {
         $request = Yii::$app->getRequest();
         $params = $request instanceof Request ? $request->getQueryParams() : [];
     }
     $currentPageSize = $pagination->getPageSize();
     $currentPage = $pagination->getPage();
     $target = $currentPage * $currentPageSize;
     $page = (int) ($target / $pageSize);
     if ($page > 0 || $page >= 0 && $pagination->forcePageParam) {
         $params[$pagination->pageParam] = $page + 1;
     } else {
         unset($params[$pagination->pageParam]);
     }
     if ($pageSize != $pagination->defaultPageSize) {
         $params[$pagination->pageSizeParam] = $pageSize;
     } else {
         unset($params[$pagination->pageSizeParam]);
     }
     $params[0] = $pagination->route === null ? Yii::$app->controller->getRoute() : $pagination->route;
     $urlManager = $pagination->urlManager === null ? Yii::$app->getUrlManager() : $pagination->urlManager;
     if ($absolute) {
         return $urlManager->createAbsoluteUrl($params);
     } else {
         return $urlManager->createUrl($params);
     }
 }
Esempio n. 2
0
 /**
  * Serializes a pagination into an array.
  * @param Pagination $pagination
  * @return array the array representation of the pagination
  * @see addPaginationHeaders()
  */
 protected function serializePagination($pagination)
 {
     return ['_links' => Link::serialize($pagination->getLinks(true)), '_meta' => ['totalCount' => $pagination->totalCount, 'pageCount' => $pagination->getPageCount(), 'currentPage' => $pagination->getPage(), 'perPage' => $pagination->getPageSize()]];
 }
Esempio n. 3
0
 /**
  * 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()]];
 }
 /**
  * 获取列表记录
  *
  * @param array|string $condition 条件
  * @param array $params 参数
  * @param string $order 排序
  * @param int $page 页码
  * @param int $pageSize 每页数量
  * @return array
  */
 public static function getListByCondition($condition = '', $params = [], $order = null, $page = 1, $pageSize = 20)
 {
     $pagination = new Pagination();
     $pagination->setPage($page);
     $pagination->setPageSize($pageSize);
     $pagination->totalCount = static::find()->innerJoinWith('menuUrl')->andWhere($condition, $params)->count(1);
     $list = static::find()->innerJoinWith('menuUrl')->andWhere($condition, $params)->offset($pagination->getOffset() - $pagination->getPageSize())->limit($pagination->getPageSize())->orderBy($order)->asArray()->all();
     return ['paginationObj' => $pagination, 'pagination' => ['currentPage' => $page, 'pageSize' => $pageSize, 'pageCount' => $pagination->getPageCount(), 'totalCount' => $pagination->totalCount], 'list' => $list];
 }
Esempio n. 5
0
 protected function cacheKeyPaginate(Pagination $paginate)
 {
     $keys = ['page' => $paginate->getPage(), 'per_page' => $paginate->getPageSize()];
     return md5(serialize($keys));
 }
Esempio n. 6
0
 /**
  * Serializes a pagination into an array.
  * @param \yii\data\Pagination $pagination
  * @return array the array representation of the pagination
  * @see addPaginationHeaders()
  */
 protected function serializePagination($pagination)
 {
     if ($this->serializedPagination !== null) {
         return $this->serializedPagination;
     }
     /** @var \yii\rest\Serializer $serializer */
     $serializer = $this->serializer;
     return $this->serializedPagination = [$serializer->linksEnvelope => \yii\web\Link::serialize($pagination->getLinks(true)), $serializer->metaEnvelope => ['totalCount' => $pagination->totalCount, 'pageCount' => $pagination->getPageCount(), 'currentPage' => $pagination->getPage() + 1, 'perPage' => $pagination->getPageSize()]];
 }