zend framework 分頁 Zend_Paginator 分頁搜尋條件
關於分頁搜尋條件分頁:
搜尋條件要求分頁後都帶有搜尋條件
頁面是一個列表頁:/admin/exam/list1.action:將一個搜尋條件的陣列賦給頁面,
$data = $db->fetchall($where);
if ($data != null) {
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Array($data));
$paginator->setItemCountPerPage(1);
$paginator->setPageRange(10);
$page = $this->_request->getParam('page',1);
$paginator->setCurrentPageNumber($page);
$this->view->data = $paginator;
}
$this->view->search = array('exam_status'=>$exam_status);
2.頁面list.phtml: echo $this->paginationControl($this->data, 'Sliding', '/common/paginator.phtml',array('param'=>$this->search));
將搜尋條件以一個數組的格式傳參到分頁的phtml
3.分頁:paginator.phtml:<?php if (isset($this->next)): ?>
<li>
<a href="<?php echo $this->url(array_merge($this->param,array('page' => $this->next))); ?>">下一頁</a>
</li>
<?php else: ?>
<li class="disabled"><a href="#">下一頁</a></li>
<?php endif; ?>
在處理分頁連結的時候,將搜尋條件陣列和page數字合併為一個數組,使用$this->url處理即可。