Contao\Pagination::generate PHP Метод

generate() публичный Метод

Generate the pagination menu and return it as HTML string
public generate ( string $strSeparator = ' ' ) : string
$strSeparator string The separator string
Результат string The pagination menu as HTML string
    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 = $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;
        // Adding rel="prev" and rel="next" links is not possible
        // anymore with unique variable names (see #3515 and #4141)
        return $objTemplate->parse();
    }

Usage Example

Пример #1
0
 /**
  * Return a pagination menu to browse results
  *
  * @return string
  */
 protected function paginationMenu()
 {
     /** @var AttributeBagInterface $objSessionBag */
     $objSessionBag = \System::getContainer()->get('session')->getBag('contao_backend');
     $session = $objSessionBag->all();
     $filter = $GLOBALS['TL_DCA'][$this->strTable]['list']['sorting']['mode'] == 4 ? $this->strTable . '_' . CURRENT_ID : $this->strTable;
     list($offset, $limit) = explode(',', $this->limit);
     // Set the limit filter based on the page number
     if (isset($_GET['lp'])) {
         $lp = intval(\Input::get('lp')) - 1;
         if ($lp >= 0 && $lp < ceil($this->total / $limit)) {
             $session['filter'][$filter]['limit'] = $lp * $limit . ',' . $limit;
             $objSessionBag->replace($session);
         }
         $this->redirect(preg_replace('/&(amp;)?lp=[^&]+/i', '', \Environment::get('request')));
     }
     if ($limit) {
         \Input::setGet('lp', $offset / $limit + 1);
     }
     $objPagination = new \Pagination($this->total, $limit, 7, 'lp', new \BackendTemplate('be_pagination'), true);
     return $objPagination->generate();
 }
All Usage Examples Of Contao\Pagination::generate