看起来这可能更简单,但我很难过。我有一个简单的控制器,可以构建一个用于输入参数的小表单。提交表单时,重新绘制相同的页面,顶部使用相同的表单,但在其下面有结果的分页视图。我的控制器在这里:
public function indexAction()
{
$form = new Application_Form_Battery();
$request = $this->getRequest();
if ($request->isPost()) {
$data = $request->getPost();
$form->populate($data);
// get the data
Zend_View_Helper_PaginationControl::setDefaultViewPartial('pagination.phtml');
$reportsTBL = new Model_DBTable_Reports();
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($reportsTBL->getBatteryLog($data)));
$paginator->setCurrentPageNumber($this->_getParam('page',1))
->setItemCountPerPage(50);
$this->view->paginator = $paginator;
}
$this->view->form = $form;
}
正如您所看到的,在提交表单后,分页结果将被view-> form语句覆盖...如何在表单提交后将它们组合起来?我不能有两个观看电话......
答案 0 :(得分:1)
有些事情在这里未经测试,
<强> indexController的强>
public function indexAction()
{
.....
$_category = new Admin_Model_DbTable_Category();
$category = $_category->browse($browseArray);
$this->view->vCount = count($category);
$paginator = Zend_Paginator::factory($category);
$page = ($postData['page'] > 0) ? $postData['page'] : 1;
$paginator->setCurrentPageNumber($page);
$paginator->setItemCountPerPage(10);
$paginator->setPageRange(5);
$this->view->categoryList = $paginator; // print_obj($paginator);
....
}
<强> index.phtml 强>
.....
<ul>
<?php if (count($this->categoryList) != 0) { ?>
<?php
foreach ($this->categoryList AS $key => $category) {
?>
<li>
<div >
<?php echo $category['name'] ?>
</div>
</li>
<?php } ?>
<li>
<div><?php echo "Total Category(" . $this->vCount . ")"; ?></div>
<div style="text-align:center;"><?php echo $this->paginationControl($this->categoryList, 'Sliding', 'pagination.phtml'); ?></div>
</li>
<?php } else { ?>
<li><div style="text-align:center;">No records found</div></li>
<?php } ?>
</ul>
...
<强> Category.php 强>
class Admin_Model_DbTable_Category extends Zend_Db_Table_Abstract
{
...
protected $_name = 'category';
protected $_primary = 'category_id';
public function browse($browseArray = array())
{
extract($browseArray);
$whereSQL = ' `parent` = 0 ';
if($category_id)
$whereSQL .= ' AND `category_id` = "'. $category_id .'"';
if($catname)
$whereSQL .= ' AND `name` = "'. $catname .'"';
if($name)
$whereSQL .= ' AND `name` LIKE "%'. $name .'%"';
if($description)
$whereSQL .= ' AND `description` LIKE "%'. $description .'%"';
if($status)
$whereSQL .= ' AND `status` = "'. $status .'"';
$select = $this->_db->select()
->from($this->_name)
->where($whereSQL);
$result = $this->getAdapter()->fetchAll($select);
return $result;
}
....
}
您可以使用名为browse的通用函数来获取表中的结果,通过使用我们可以在呈现页面时对数据进行分页的结果。
答案 1 :(得分:0)
我解决了。我正在使用一个调用表单模板的视图,我试图在该表单上显示分页结果。我将分页结果移动到实际的视图脚本,一切都解决了。
感谢您的帮助。