symfony分页

1.action.class.php
  

  
  
  
  
  1. $q = Doctrine_Core::getTable('cmsContent')->findAll();
  2.    //分页 
  3.    $this->pg=new sfDoctrinePager('modelName',3); 
  4.    $this->pg->setQuery($q); 
  5.    $this->pg->setPage($page,1); 
  6.    $this->pg->init(); 



2.模板代码:
 

  
  
  
  
  1. <?php if ($pager->haveToPaginate()): ?> 
  2.   <div class="pagination"> 
  3.     <a href="<?php echo url_for('category', $category) ?>?page=1"> 
  4.       <img src="/images/first.png" alt="First page" title="First page" /> 
  5.     </a> 
  6.   
  7.     <a href="<?php echo url_for('category', $category) ?>?page=<?php echo $pager->getPreviousPage() ?>"> 
  8.       <img src="/images/previous.png" alt="Previous page" title="Previous page" /> 
  9.     </a> 
  10.   
  11.     <?php foreach ($pager->getLinks() as $page): ?> 
  12.       <?php if ($page == $pager->getPage()): ?> 
  13.         <?php echo $page ?> 
  14.       <?php else: ?> 
  15.         <a href="<?php echo url_for('category', $category) ?>?page=<?php echo $page ?>"><?php echo $page ?></a> 
  16.       <?php endif; ?> 
  17.     <?php endforeach; ?> 
  18.   
  19.     <a href="<?php echo url_for('category', $category) ?>?page=<?php echo $pager->getNextPage() ?>"> 
  20.       <img src="/images/next.png" alt="Next page" title="Next page" /> 
  21.     </a> 
  22.   
  23.     <a href="<?php echo url_for('category', $category) ?>?page=<?php echo $pager->getLastPage() ?>"> 
  24.       <img src="/images/last.png" alt="Last page" title="Last page" /> 
  25.     </a> 
  26.   </div> 
  27. <?php endif; ?> 
  28.   
  29. <div class="pagination_desc"> 
  30.   <strong><?php echo count($pager) ?></strong> jobs in this category 
  31.   
  32.   <?php if ($pager->haveToPaginate()): ?> 
  33.     - page <strong><?php echo $pager->getPage() ?>/<?php echo $pager->getLastPage() ?></strong> 
  34.   <?php endif; ?> 
  35. </div> 



模板所使用的sfDoctrinePager方法列表:

    getResults(): 为当前页返回Doctrine对象数组
    getNbResults(): 返回记录总数
    haveToPaginate(): 当页数超过一页,则返回true
    getLinks(): 返回页面链接列表
    getPage(): 返回当前页码
    getPreviousPage(): 返回前一页页码
    getNextPage(): 返回下一页页码
    getLastPage(): 返回最后一页页码

 

你可能感兴趣的:(symfony)