yii\data\Pagination::getPageSize PHP Method

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.
    public function getPageSize()
    {
        if ($this->_pageSize === null) {
            if (empty($this->pageSizeLimit)) {
                $pageSize = $this->defaultPageSize;
                $this->setPageSize($pageSize);
            } else {
                $pageSize = (int) $this->getQueryParam($this->pageSizeParam, $this->defaultPageSize);
                $this->setPageSize($pageSize, true);
            }
        }
        return $this->_pageSize;
    }

Usage Example

示例#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);
     }
 }
All Usage Examples Of yii\data\Pagination::getPageSize