core-bundle/src/Resources/contao/library/Contao/Pagination.php
public function generate($strSeparator=' ')
	{
		if ($this->intRowsPerPage < 1)
		{
			return '';
		}

		$blnQuery = false;
		list($this->strUrl) = explode('?', Environment::get('request'), 2);

		// Prepare the URL
		foreach (preg_split('/&(amp;)?/', Environment::get('queryString'), -1, PREG_SPLIT_NO_EMPTY) as $fragment)
		{
			if (strpos($fragment, $this->strParameter . '=') === false)
			{
				$this->strUrl .= (!$blnQuery ? '?' : '&amp;') . $fragment;
				$blnQuery = true;
			}
		}

		$this->strVarConnector = $blnQuery ? '&amp;' : '?';
		$this->intTotalPages = ceil($this->intRows / $this->intRowsPerPage);

		// Return if there is only one page
		if ($this->intTotalPages < 2 || $this->intRows < 1)
		{
			return '';
		}

		if ($this->intPage > $this->intTotalPages)
		{
			$this->intPage = $this->intTotalPages;
		}

		$objTemplate = $this->objTemplate;

		$objTemplate->hasFirst = $this->hasFirst();
		$objTemplate->hasPrevious = $this->hasPrevious();
		$objTemplate->hasNext = $this->hasNext();
		$objTemplate->hasLast = $this->hasLast();

		// Deprecated since Contao 4.0, to be removed in Contao 5.0
		$objTemplate->items = function () use ($strSeparator)
		{
			@trigger_error('Using $pagination->items has been deprecated and will no longer work in Contao 5.0. Use $pagination->pages instead.', E_USER_DEPRECATED);

			return $this->getItemsAsString($strSeparator);
		};

		$objTemplate->pages = $this->getItemsAsArray();
		$objTemplate->total = sprintf($this->lblTotal, $this->intPage, $this->intTotalPages);

		$objTemplate->first = array
		(
			'link' => $this->lblFirst,
			'href' => $this->linkToPage(1),
			'title' => sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), 1)
		);

		$objTemplate->previous = array
		(
			'link' => $this->lblPrevious,
			'href' => $this->linkToPage($this->intPage - 1),
			'title' => sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), ($this->intPage - 1))
		);

		$objTemplate->next = array
		(
			'link' => $this->lblNext,
			'href' => $this->linkToPage($this->intPage + 1),
			'title' => sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), ($this->intPage + 1))
		);

		$objTemplate->last = array
		(
			'link' => $this->lblLast,
			'href' => $this->linkToPage($this->intTotalPages),
			'title' => sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), $this->intTotalPages)
		);

		$objTemplate->class = 'pagination-' . $this->strParameter;
		$objTemplate->pagination = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['pagination']);

		// Adding rel="prev" and rel="next" links is not possible
		// anymore with unique variable names (see #3515 and #4141)

		return $objTemplate->parse();
	}
public function generate($strSeparator=' ')
	{
		if ($this->intRowsPerPage < 1)
		{
			return '';
		}

		$blnQuery = false;
		list($this->strUrl) = explode('?', Environment::get('request'), 2);

		// Prepare the URL
		foreach (preg_split('/&(amp;)?/', Environment::get('queryString'), -1, PREG_SPLIT_NO_EMPTY) as $fragment)
		{
			if (strpos($fragment, $this->strParameter . '=') === false)
			{
				$this->strUrl .= (!$blnQuery ? '?' : '&amp;') . $fragment;
				$blnQuery = true;
			}
		}

		$this->strVarConnector = $blnQuery ? '&amp;' : '?';
		$this->intTotalPages = ceil($this->intRows / $this->intRowsPerPage);

		// Return if there is only one page
		if ($this->intTotalPages < 2 || $this->intRows < 1)
		{
			return '';
		}

		if ($this->intPage > $this->intTotalPages)
		{
			$this->intPage = $this->intTotalPages;
		}

		$objTemplate = $this->objTemplate;

		$objTemplate->hasFirst = $this->hasFirst();
		$objTemplate->hasPrevious = $this->hasPrevious();
		$objTemplate->hasNext = $this->hasNext();
		$objTemplate->hasLast = $this->hasLast();

		// Deprecated since Contao 4.0, to be removed in Contao 5.0
		$objTemplate->items = function () use ($strSeparator)
		{
			@trigger_error('Using $pagination->items has been deprecated and will no longer work in Contao 5.0. Use $pagination->pages instead.', E_USER_DEPRECATED);

			return $this->getItemsAsString($strSeparator);
		};

		$objTemplate->pages = $this->getItemsAsArray();
		$objTemplate->total = sprintf($this->lblTotal, $this->intPage, $this->intTotalPages);

		$objTemplate->first = array
		(
			'link' => $this->lblFirst,
			'href' => $this->linkToPage(1),
			'title' => sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), 1)
		);

		$objTemplate->previous = array
		(
			'link' => $this->lblPrevious,
			'href' => $this->linkToPage($this->intPage - 1),
			'title' => sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), ($this->intPage - 1))
		);

		$objTemplate->next = array
		(
			'link' => $this->lblNext,
			'href' => $this->linkToPage($this->intPage + 1),
			'title' => sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), ($this->intPage + 1))
		);

		$objTemplate->last = array
		(
			'link' => $this->lblLast,
			'href' => $this->linkToPage($this->intTotalPages),
			'title' => sprintf(StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['goToPage']), $this->intTotalPages)
		);

		$objTemplate->class = 'pagination-' . $this->strParameter;
		$objTemplate->pagination = StringUtil::specialchars($GLOBALS['TL_LANG']['MSC']['pagination']);

		// Adding rel="prev" and rel="next" links is not possible
		// anymore with unique variable names (see #3515 and #4141)

		return $objTemplate->parse();
	}
public function generate ( $ strSeparator = ' ' ) { if ( $ this -> intRowsPerPage < 1 ) { return '' ; } $ blnQuery = false ; list ( $ this -> strUrl ) = explode ( '?' , Environment :: get ( 'request' ) , 2 ) ; // Prepare the URL foreach ( preg_split ( '/&(amp;)?/' , Environment :: get ( 'queryString' ) , - 1 , PREG_SPLIT_NO_EMPTY ) as $ fragment ) { if ( strpos ( $ fragment , $ this -> strParameter . '=' ) === false ) { $ this -> strUrl .= ( ! $ blnQuery ? '?' : '&amp;' ) . $ fragment ; $ blnQuery = true ; } } $ this -> strVarConnector = $ blnQuery ? '&amp;' : '?' ; $ this -> intTotalPages = ceil ( $ this -> intRows / $ this -> intRowsPerPage ) ; // Return if there is only one page if ( $ this -> intTotalPages < 2 || $ this -> intRows < 1 ) { return '' ; } if ( $ this -> intPage > $ this -> intTotalPages ) { $ this -> intPage = $ this -> intTotalPages ; } $ objTemplate = $ this -> objTemplate ; $ objTemplate -> hasFirst = $ this -> hasFirst ( ) ; $ objTemplate -> hasPrevious = $ this -> hasPrevious ( ) ; $ objTemplate -> hasNext = $ this -> hasNext ( ) ; $ objTemplate -> hasLast = $ this -> hasLast ( ) ; // Deprecated since Contao 4.0, to be removed in Contao 5.0 $ objTemplate -> items = function ( ) use ( $ strSeparator ) { @ trigger_error ( 'Using $pagination->items has been deprecated and will no longer work in Contao 5.0. Use $pagination->pages instead.' , E_USER_DEPRECATED ) ; return $ this -> getItemsAsString ( $ strSeparator ) ; } ; $ objTemplate -> pages = $ this -> getItemsAsArray ( ) ; $ objTemplate -> total = sprintf ( $ this -> lblTotal , $ this -> intPage , $ this -> intTotalPages ) ; $ objTemplate -> first = array ( 'link' => $ this -> lblFirst , 'href' => $ this -> linkToPage ( 1 ) , 'title' => sprintf ( StringUtil :: specialchars ( $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'goToPage' ] ) , 1 ) ) ; $ objTemplate -> previous = array ( 'link' => $ this -> lblPrevious , 'href' => $ this -> linkToPage ( $ this -> intPage - 1 ) , 'title' => sprintf ( StringUtil :: specialchars ( $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'goToPage' ] ) , ( $ this -> intPage - 1 ) ) ) ; $ objTemplate -> next = array ( 'link' => $ this -> lblNext , 'href' => $ this -> linkToPage ( $ this -> intPage + 1 ) , 'title' => sprintf ( StringUtil :: specialchars ( $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'goToPage' ] ) , ( $ this -> intPage + 1 ) ) ) ; $ objTemplate -> last = array ( 'link' => $ this -> lblLast , 'href' => $ this -> linkToPage ( $ this -> intTotalPages ) , 'title' => sprintf ( StringUtil :: specialchars ( $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'goToPage' ] ) , $ this -> intTotalPages ) ) ; $ objTemplate -> class = 'pagination-' . $ this -> strParameter ; $ objTemplate -> pagination = StringUtil :: specialchars ( $ GLOBALS [ 'TL_LANG' ] [ 'MSC' ] [ 'pagination' ] ) ; // Adding rel="prev" and rel="next" links is not possible // anymore with unique variable names (see #3515 and #4141) return $ objTemplate -> parse ( ) ; }
Generate the pagination menu and return it as HTML string

@param string $strSeparator The separator string

@return string The pagination menu as HTML string
Generate the pagination menu and return it as HTML string