[TYPO3-english] Problem with fluid pagination - First page link doesn´t work

Angela Checa angelachek at gmail.com
Wed Feb 10 23:27:49 CET 2016


Hello, I´m new with typo3 amd fluid, I need a little help with this issue:

I have the paginateController like this:

class PaginateController extends \TYPO3\CMS\Fluid\Core\Widget\AbstractWidgetController {

	
	protected $configuration = array('itemsPerPage' => 10, 'insertAbove' => FALSE, 'insertBelow' => TRUE, 'maximumNumberOfLinks' => 99, 'addQueryStringMethod' => '');

	/**
	 * @var \TYPO3\CMS\Extbase\Persistence\QueryResultInterface
	 */
protected $currentPage = 1;

	protected $maximumNumberOfLinks = 99;


	protected $numberOfPages = 1;

	
	public function initializeAction() {
		$this->objects = $this->widgetConfiguration['objects'];
		\TYPO3\CMS\Core\Utility\ArrayUtility::mergeRecursiveWithOverrule($this->configuration, $this->widgetConfiguration['configuration'], FALSE);
		$this->numberOfPages = ceil(count($this->objects) / (int)$this->configuration['itemsPerPage']);
		$this->maximumNumberOfLinks = (int)$this->configuration['maximumNumberOfLinks'];
	}

	/**
	 * @param integer $currentPage
	 * @return void
	 */
	public function indexAction($currentPage = 1) {
		// set current page
		$this->currentPage = (int)$currentPage;
		if ($this->currentPage < 1) {
			$this->currentPage = 1;
		}
		if ($this->currentPage > $this->numberOfPages) {
			// set $modifiedObjects to NULL if the page does not exist
			$modifiedObjects = NULL;
		} else {
			// modify query
			$itemsPerPage = (int)$this->configuration['itemsPerPage'];
			$query = $this->objects->getQuery();
			$query->setLimit($itemsPerPage);
			if ($this->currentPage > 1) {
				$query->setOffset((int)($itemsPerPage * ($this->currentPage - 1)));
			}
			$modifiedObjects = $query->execute();
		}
		$this->view->assign('contentArguments', array(
			$this->widgetConfiguration['as'] => $modifiedObjects
		));
		$this->view->assign('configuration', $this->configuration);
		$this->view->assign('pagination', $this->buildPagination());
	}

	/**
	 * If a certain number of links should be displayed, adjust before and after
	 * amounts accordingly.
	 *
	 * @return void
	 */
	protected function calculateDisplayRange() {
		$maximumNumberOfLinks = $this->maximumNumberOfLinks;
		if ($maximumNumberOfLinks > $this->numberOfPages) {
			$maximumNumberOfLinks = $this->numberOfPages;
		}
		$delta = floor($maximumNumberOfLinks / 2);
		$this->displayRangeStart = $this->currentPage - $delta;
		$this->displayRangeEnd = $this->currentPage + $delta - ($maximumNumberOfLinks % 2 === 0 ? 1 : 0);
		if ($this->displayRangeStart < 1) {
			$this->displayRangeEnd -= $this->displayRangeStart - 1;
		}
		if ($this->displayRangeEnd > $this->numberOfPages) {
			$this->displayRangeStart -= $this->displayRangeEnd - $this->numberOfPages;
		}
		$this->displayRangeStart = (int)max($this->displayRangeStart, 1);
		$this->displayRangeEnd = (int)min($this->displayRangeEnd, $this->numberOfPages);
	}

	/**
	 * Returns an array with the keys "pages", "current", "numberOfPages", "nextPage" & "previousPage"
	 *
	 * @return array
	 */
	protected function buildPagination() {
		$this->calculateDisplayRange();
		$pages = array();
		for ($i = $this->displayRangeStart; $i <= $this->displayRangeEnd; $i++) {
			$pages[] = array('number' => $i, 'isCurrent' => $i === $this->currentPage);
		}
		$pagination = array(
			'pages' => $pages,
			'current' => $this->currentPage,
			'numberOfPages' => $this->numberOfPages,
			'displayRangeStart' => $this->displayRangeStart,
			'displayRangeEnd' => $this->displayRangeEnd,
			'hasLessPages' => $this->displayRangeStart > 2,
			'hasMorePages' => $this->displayRangeEnd + 1 < $this->numberOfPages
		);
		if ($this->currentPage < $this->numberOfPages) {
			$pagination['nextPage'] = $this->currentPage + 1;
		}
		if ($this->currentPage >1) {
			$pagination['previousPage'] = $this->currentPage-1;
		}
		return $pagination;
	}
}


In my action html file I have this fragment to paginate query results

<f:if condition="{items->f:count()} > {limit}">
          <f:then>    
    		<f:widget.paginate objects="{items}" as="item" configuration="{itemsPerPage: limit, maximumNumberOfLinks: 7}">
				<f:for each="{item}" as="i" iteration="iter">
    				<div class="famName">{i.taxon.taxonPadre.nombre}</div>
					<f:render section="singleItem" arguments="{elm:i}"/>
				</f:for>
			</f:widget.paginate>
   		 </f:then> 
     <f:else>
          	<f:for each="{items}" as="i" iteration="iter">
    			<div class="famName">{i.taxon.taxonPadre.nombre}</div>
				<f:render section="singleItem" arguments="{elm:i}"/>
			</f:for>
     </f:else>
   </f:if>

Paginator works fine at the fist time the results page is  loaded since first page is displayed,  I can navigate through the other pages with the pagination links,  but when I clicked the link 1 to back to the first page, the link doesn´t point out to first page,  href attribute is set with the url and its currentPage argument has the number of current page instead of currentPage=1, then I can´t return to first page.

Please, let me know if the controller need something else, or if I have to do something extra  in the configuration.

Angie.
 






More information about the TYPO3-english mailing list