Zend_Paginator. Wrong moving to the next page.

For programming and general questions on Zend Framework
Post Reply
anas355
Posts: 3
Joined: Mon Apr 18, 2016 11:16 am

Zend_Paginator. Wrong moving to the next page.

Post by anas355 » Mon May 30, 2016 9:27 am

Please, help!

Unfortunately I have no right to send the site address, so I will try to explain in words.

I have site on zf2. On the first page I output all select elements from table, that divided by paginator. There is a search engine on my site. The search result output in the same view if user press "search" button. Method to transfer the selections is POST. The engine works correct, the problem appear when user try to navigate between pages, when he is searching something. If after searching I try to move at the next page, the search disappears and opens the all items, not searching elements on the next page. For example, when I search something, and try to move between searching pages, instead of page "2" with searching results I get page of all select results from table.

There is code of me controller:

Code: Select all

	 public function indexAction()
    {
			 
			$view = new ViewModel();
			$form = $this->getServiceLocator()->get('MyForm');
			$filterObj = new ViewModel(array('form'=>$form));
			$filterObj->setTemplate('index/filter');
			
			$searchList = array();
			if (isset($_POST["submit"]))
			{
			if((isset($_POST["section"]))) { $searchList["section"] = $_POST["section"];}
			if((isset($_POST["view_presentation"]))) { $searchList["view_presentation"] = $_POST["view_presentation"];}
			if((isset($_POST["access"]))) { $searchList["access"] = $_POST["access"];}}

			$paginator = $this->getBookTable()->getBooksearch(true,$searchList);

			$paginator->setCurrentPageNumber((int) $this->params()->fromQuery('page', 1));
			$paginator->setItemCountPerPage(8);

			
			$outputObj = new ViewModel(array(
			'paginator' => $paginator,
			'form'=>$form,
			));
			$outputObj->setTemplate('index/output');
			
			$view->addChild($filterObj, 'filter');
			$view->addChild($outputObj, 'output');

				return $view;
		

    }
The next is the output pagination in the view:

Code: Select all

<div class="pagination">
<?php
		echo $this->paginationControl(
		$this->paginator,
		'sliding',
		'partial/paginator.phtml'
		);
?>
</div>
And the pagination engine, that is in the view/partial:

Code: Select all

<?php if ($this->pageCount): ?>
	<div>
	<ul class="pagination">
	<!-- Previous page link -->
	<?php if (isset($this->previous)): ?>
	<li>
	<a href="<?php echo $this->url($this->route); ?>?page=<?php echo $this->previous; ?> ">
	<<
	</a>
	</li>
	<?php else: ?>
	<li class="disabled">
	<a href="#">
	<<
	</a>
	</li>
	<?php endif; ?>

	<!-- Numbered page links -->
	<?php foreach ($this->pagesInRange as $page): ?>
	<?php if ($page != $this->current): ?>
	<li>
	<a href="<?php echo $this->url($this->route);?>?page=<?php echo $page; ?>">
	<?php echo $page; ?>
	</a>
	</li>
	<?php else: ?>
	<li class="active">
	<a href="#"><?php echo $page; ?></a>
	</li>
	<?php endif; ?>
	<?php endforeach; ?>
	<!-- Next page link -->
	<?php if (isset($this->next)): ?>
	<li>
	<a href="<?php echo $this->url($this->route); ?>?page=<?php echo $this->next; ?>">
	>>
	</a>
	</li>
	<?php else: ?>
	<li class="disabled">
	<a href="#">
	>>
	</a>
	</li>
	<?php endif; ?>
	</ul>
	</div>
<?php endif; ?>

stij2324
Posts: 55
Joined: Fri Nov 06, 2015 11:42 pm

Re: Zend_Paginator. Wrong moving to the next page.

Post by stij2324 » Fri Jun 03, 2016 1:56 pm

After taking a quick looks it because you have are using post to post teh data.
You can stire them in a session and if there are no posted data the you can use the data from session.

Remember if you do it like that you also have to make an option to clear that session.

Post Reply