Jump to content

Archived

This topic is now archived and is closed to further replies.

s_ainley87

Zend Pagination Problem

Recommended Posts

Hello,

 

I am having a problem with my zend pagination, in that it is not pagination at, I try and set a limit of 4 record per page but it ignores, I can for the life in me see the problem I was hoping someone with sharp eyes could?

 

model

public function getAllNews()
{
	$db = Zend_Registry::get('db');

	$sql = "SELECT * FROM $this->_name WHERE flag = 1 ORDER BY created_at";

	$query = $db->query($sql);
	while ($row = $query->fetchAll()) {
    		$result[] = $row;
	}

	return $result;
}

 

controller

$this->_helper->layout->setLayout('latestnews');
	Zend_Loader::loadClass('newsArticles');
	$allNews = new newsArticles();
	$this->view->allNews = $allNews->getAllnews();
	//die (var_dump($this->view->allNews));
	$data = $this->view->allNews;
	// Instantiate the Zend Paginator and give it the Zend_Db_Select instance  Argument ($selection)
        $paginator = Zend_Paginator::factory($data);
	// Set parameters for paginator
        $paginator->setCurrentPageNumber($this->_getParam("page"));
        $paginator->setItemCountPerPage(4);
        $paginator->setPageRange(4);
	// Make paginator available in your views
        $this->view->paginator = $paginator;
	//die(var_dump($data));

 

view

<div id="rightColumn">
			<h3>Latest News</h3>
			<?php if (count($this->paginator)): ?>
				<ul>
					<?php foreach ($this->paginator as $item): ?>
						<?php
						foreach ($item as $k => $v)
						{
							echo "<li>" . $v['title'] . "</li>";
						}
						?>

					<?php endforeach; ?>
				</ul>
			<?php endif; ?>

<?= $this->paginationControl($this->paginator, 'Sliding', '/latestnews/partial_pagination_control.phtml'); ?> 
			</div>

 

pagination_template

<?php if ($this->pageCount): ?> 
<div class="paginationControl">
<!-- Previous page link --> 
<?php if (isset($this->previous)): ?> 
  <a href="<?= $this->url(array('page' => $this->previous)); ?>">< Previous</a> | 
<?php else: ?> 
  <span class="disabled">< Previous</span> | 
<?php endif; ?> 

<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?> 
  <?php if ($page != $this->current): ?>
    <a href="<?= $this->url(array('page' => $page)); ?>"><?= $page; ?></a> | 
  <?php else: ?>
    <?= $page; ?> | 
  <?php endif; ?>
<?php endforeach; ?>

<!-- Next page link --> 
<?php if (isset($this->next)): ?> 
  <a href="<?= $this->url(array('page' => $this->next)); ?>">Next ></a>
<?php else: ?> 
  <span class="disabled">Next ></span>
<?php endif; ?> 
</div> 
<?php endif; ?> 

 

 

Any help would be great as I cannot work it out.

Thanks everyone

 

Share this post


Link to post
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.