在zend Paginator中添加(显示当前开始到Total条目的条目数)

时间:2012-01-31 13:48:44

标签: zend-framework zend-paginator

我想做的是我wana向用户展示这个

Showing 1 to  10 of 50 entries
Showing 11 to 20 of 50 entries
Showing 21 to 30 of 50 entries
Showing 31 to 40 of 50 entries
Showing 41 to 50 of 50 entries

我在我的app中使用了Zend Paginator,让我们说

 Showing A to B of C entries

我很容易找到等于

的C.
 $result = $DB->fetchAll($sql);
 $total =count($result); 

如果我们在这里看到

 $page=$this->_getParam('page',1);
 //here we can get the requested page#.
 //lets hard code this
  $paginator->setItemCountPerPage(10);
  $per_page =10; 
  in my view   count($this->paginator)   give me total number of pages that is if
  if        total = 101     = $total
  than      page = 9        = $page
 and        paginator = 11  = count($this->paginator)

我怎样才能实现这一目标,但通用意味着可以使用next,previous等...

1 个答案:

答案 0 :(得分:1)

  

显示C条目的A到B

大致是这样的:

$page = $paginator->getCurrentPageNumber();
$perPage = $paginator->getItemCountPerPage();
$total = $paginator->getTotalItemCount();

$A = ($page - 1) * $perPage + 1;
$B = min($A + $perPage - 1, $total);
$C = $total;