在controller中寫入:
private $_aghqmztj;
public function init()
{
}
public function indexAction()
{
$numPerPage = 10;
$page = $this->_request->getParam('page',1);
$offset = $numPerPage*$page;
$_aghqmztj=new Model_DbTable_Aghqmztj();
$stockCodeList = $_aghqmztj->getStockCodeList();
$paginator = Zend_Paginator::factory($stockCodeList);
$paginator->setCurrentPageNumber($page)
->setItemCountPerPage($numPerPage)
->setPageRange(8);
$this->view->paginator = $paginator;
}
在該Action的視圖文件中寫入:
<?php if( count($this->paginator) ):?>
<?php foreach ($this->paginator as $item): ?>
<ul>
<li><?php echo $item['Aghqjtsj02'];?></li>
</ul>
<?php endforeach;?>
<?php endif;?>
<?php echo $this->paginationControl($this->paginator,'Elastic','pagelist.phtml');?>
在view目錄下的創建pagelist.phtml文件:
<?php if($this->pageCount):?>
<div class="paginationControl">
<?php if( isset($this->first) ):?>
<a href="<?php echo $this->url(array('controller'=>'search','action'=>'index','page'=>$this->first));?>"><首頁</a>
<?php else: ?>
<span class="disabled"><首頁</span>
<?php endif;?>
<?php if( isset($this->previous) ):?>
<a href="<?php echo $this->url(array('controller'=>'search','action'=>'index','page'=>$this->previous));?>"><上一頁</a>
<?php else: ?>
<span class="disabled"><上一頁</span>
<?php endif;?>
<?php foreach ($this->pagesInRange as $page):?>
<?php if($page !=$this->current):?>
<a href="<?php echo $this->url(array('controller'=>'search','action'=>'index','page'=>$page));?>"><?php echo $page;?></a>|
<?php else :?>
<?php echo $page;?>|
<?php endif;?>
<?php endforeach;?>
<?php if(isset($this->next)):?>
<a href="<?php echo $this->url(array('controller'=>'search','action'=>'index','page'=>$this->next));?>">下一頁></a>
<?php else:?>
<span class="disabled" >下一頁></span>
<?php endif;?>
<?php if( isset($this->last) ):?>
<a href="<?php echo $this->url(array('controller'=>'search','action'=>'index','page'=>$this->last));?>">尾頁></a>
<?php else: ?>
<span class="disabled">尾頁></span>
<?php endif;?>
<span>第<?php echo $this->current;?>頁</span>
<span>共<?php echo $this->pageCount;?>頁</span>
<span>共<?php echo $this->totalItemCount;?>條</span>
</div>
<?php endif;?>