yii\data\Pagination::createUrl PHP Method

createUrl() public method

This method is mainly called by pagers when creating URLs used to perform pagination.
See also: params
See also: forcePageParam
public createUrl ( integer $page, integer $pageSize = null, boolean $absolute = false ) : string
$page integer the zero-based page number that the URL should point to.
$pageSize integer the number of items on each page. If not set, the value of [[pageSize]] will be used.
$absolute boolean whether to create an absolute URL. Defaults to `false`.
return string the created URL
    public function createUrl($page, $pageSize = null, $absolute = false)
    {
        $page = (int) $page;
        $pageSize = (int) $pageSize;
        if (($params = $this->params) === null) {
            $request = Yii::$app->getRequest();
            $params = $request instanceof Request ? $request->getQueryParams() : [];
        }
        if ($page > 0 || $page == 0 && $this->forcePageParam) {
            $params[$this->pageParam] = $page + 1;
        } else {
            unset($params[$this->pageParam]);
        }
        if ($pageSize <= 0) {
            $pageSize = $this->getPageSize();
        }
        if ($pageSize != $this->defaultPageSize) {
            $params[$this->pageSizeParam] = $pageSize;
        } else {
            unset($params[$this->pageSizeParam]);
        }
        $params[0] = $this->route === null ? Yii::$app->controller->getRoute() : $this->route;
        $urlManager = $this->urlManager === null ? Yii::$app->getUrlManager() : $this->urlManager;
        if ($absolute) {
            return $urlManager->createAbsoluteUrl($params);
        } else {
            return $urlManager->createUrl($params);
        }
    }

Usage Example

示例#1
0
 /**
  * @depends testCreateUrl
  */
 public function testForcePageParam()
 {
     $pagination = new Pagination();
     $pagination->route = 'item/list';
     $pagination->forcePageParam = true;
     $this->assertEquals('/index.php?r=item%2Flist&page=1', $pagination->createUrl(0));
     $pagination->forcePageParam = false;
     $this->assertEquals('/index.php?r=item%2Flist', $pagination->createUrl(0));
 }
All Usage Examples Of yii\data\Pagination::createUrl