Zend_Paginator分页代码

Standard

Models
Book.php

class Book extends Zend_Db_Table {
  ...
}

Controllers
IndexController.php

class IndexController extends Zend_Controller_Action {
 
  function init() {
    $this->initView();
    //set baseUrl
    $this->view->baseUrl = $this->_request->getBaseUrl();
  }
 
  function indexAction() {
    $this->view->title = "Title";
    $book = new Book();
    $this->view->books = $book->index();
 
    $pageNumber = 2;
    $paginator = Zend_Paginator::factory($this->view->books);
    $paginator->setItemCountPerPage($pageNumber);
    $paginator->setCurrentPageNumber($this->_getParam('page'));
    Zend_Paginator::setDefaultScrollingStyle('Sliding');
    $paginator->setView($this->view);
 
    $this->view->books = $paginator;
 
    $this->view->paginator = $paginator;
 
    $this->render();
  }
}

Views
views\scripts\index\index.phtml

<?php foreach ($this->books as $item) {?>
<ul id='ul_<?php echo $this->escape($item->id) ?>'>
  <li>
  <table width="100%"><tr><td width="60%">[<?php echo $this->escape($item->username) ?>]</b> Create by:<?php echo $this->escape($item->pubdate) ?></td><td align="right"><a href="<?php echo $this->baseUrl ?>/index/add/id/<?php echo $item->id ?>?height=280&width=280" class="thickbox" title="Edit">EDIT</a> <a href="#" id="del_<?php echo $this->escape($item->id) ?>" class="del">DEL</a></td></tr></table>
  </li>
  <li class="bottom"><?php echo nl2br($this->escape($item->content)) ?></li>
</ul>
<?php } ?>
<ul>
  <li>
  <?php echo $this->paginationControl($this->paginator, 'Elastic', 'pagelist.phtml'); ?>
  </li>
</ul>

views\scripts\pagelist.phtml

<?php if ($this->pageCount): ?>
<!-- yemaosheng.com -->
<div class="paginationControl">
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
   <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'index', 'page'=>$this->previous)); ?>">< 上一页</a> |
<?php else: ?>
   <span class="disabled">< 上一页</span> |
<?php endif; ?>
<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
  <?php if ($page != $this->current): ?>
     <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'index', 'page'=>$page)); ?>"><?= $page; ?></a> |
  <?php else: ?>
    <?= $page; ?> |
  <?php endif; ?>
<?php endforeach; ?>
<!-- Next page link -->
<?php if (isset($this->next)): ?>
   <a href="<?php echo $this->url(array('controller'=>'index', 'action'=>'index', 'page'=>$this->next)); ?>">下一页 ></a>
<?php else: ?>
   <span class="disabled">下一页 ></span>
<?php endif; ?>
</div>
<?php endif; ?>

转载请写明出处: http://yemaosheng.com

One thought on “Zend_Paginator分页代码

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.