我当前正在尝试对从数据库返回的信息进行分页。
我目前使用的是Zend 1.12版本,对于Zend和MVC来说是非常新的版本。因此,我非常感谢任何关于我的代码的更好布局的建议,以符合最佳实践,以及正确方向上的一点,即我的分页代码工作所缺少的内容
到目前为止,我已经看了几个教程:This,This,This,and This,并查看了一些堆栈溢出问题,包括This question。但我肯定遗漏了什么,因为我不能让它工作。
我已经设法将显示的结果集限制为我选择的数量(30),并且我已经设法显示分页控件。
不幸的是,我的分页控件不起作用。
问题
当我单击“下一步”时,地址栏将从site/model/controller转到site/model/controller/page/2,但显示不会改变。
当我单击最后一个时,地址栏将从
site/model/controller/page/2到site/model/controller/page/29 (这是我期望的分页后的页数)。显示不变。
我不能单击上一页(即使我在第29页),因为它不是活动链接(它在HTML代码中被禁用)。
我的代码如下:
模型
public function readAll()
{
$tableData = new Application_Model_DbTable_Bins();
$table = $tableData->fetchAll();
if (!empty($table)) {
return $table;
} else {
return 'There is no information held within this table';
}
}控制器
public function readallAction($items = 10, $page = 1)
{
$readAll = new Application_Model_Bins();
$paginator = Zend_Paginator::factory($readAll->readAll());
$paginator->setItemCountPerPage($items);
$paginator->setCurrentPageNumber($page);
if ( empty ( $page ) ) { $page = 1; }
$this->view->readall = $paginator;
}视图
<div id="view-content">
<form method='post' id="bins" name="myform">
<table border="1">
<th>BIN</th>
<th>COMP_DIV</th>
<th>STY_RET_TYPE</th>
<th>STY_PDT_TYPE</th>
<th>PRICE_POINT</th>
<th>STORAGE_TYPE</th>
<?php echo $this->partialLoop('partials/bins.phtml', $this->readall); ?>
<td><input type=checkbox value="Check All" onClick="this.value=check(this.form.list)" /></td>
</table>
<input type='submit' name='submit' value='move' />
</form>
<?php echo $this->paginationControl($this->readall, 'Sliding', 'pagination_controls.phtml'); ?>
分页控件
<?php if ($this->pageCount): ?>
<!-- first Page Link-->
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('page' => $this->first)); ?>">First</a> |
<?php else: ?>
<span class="disabled">First</span> |
<?php endif; ?>
<!-- previous Pagelink-->
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('page' => $this->previous)); ?>">< Previous</a> |
<?php else: ?>
<span class="disabled">< Previous</span> |
<?php endif; ?>
<!-- next Page link-->
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('page' => $this->next)); ?>">Next ></a> |
<?php else: ?>
<span class="disabled">Next ></span> |
<?php endif; ?>
<!-- Last page link-->
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('page' => $this->last)); ?>">Last</a>
<?php else: ?>
<span class="disabled">Last</span>
<?php endif; ?>发布于 2013-07-13 20:49:28
使用
$page = $this->_getParam('page',1);
$paginator = Zend_Paginator::factory($result);
$paginator->setItemCountPerPage(5);
$paginator->setCurrentPageNumber($page);
$this->view->paginator = $paginatorhttps://stackoverflow.com/questions/16964337
复制相似问题