Studyon Minte9.com
ZF 1.0




Paginator



// parent controller
public function setPaginator($data) {
	$this->view->addScriptPath('../Application/layouts/');
	Zend_View_Helper_PaginationControl::setDefaultViewPartial('partials/paginator.phtml');
	Zend_Paginator::setDefaultScrollingStyle('Sliding');
	     
	$data->setItemCountPerPage(10);
	$data->setCurrentPageNumber(Zend_Filter_Int::$this->_getParam('page'));
	$data->setPageRange(5);
}

// controller
$data = $articleModel->getArticles();
parent::setPaginator($data);
$this->view->articles = $data;


// or ... ( model extends Zend_Db_Table)
$sql = $articleModel->select()->order('id DESC');
$paginator = $this->createPaginator($sql);
$paginator->setItemCountPerPage(5);
$this->view->paginator = $paginator;


// model
$sql = "...";
$data = Zend_Paginator::factory($sql);  


// view
<?php foreach($this->articles as $k => $v): ?>
	...
<?php endforeach; ?>
<?php echo $this->paginationControl($this->articles); ?>


//layouts/partials/paginator.phtml
<?php if ($this->pageCount): ?>

    <div id='pagination'>
        
        <!-- First page link -->
        <?php if (isset($this->first) && ($this->first != $this->current) ): ?>
          <a class="letter-page" href="<?= $this->url(array('page' => ""),$this->route); ?>">&laquo;&laquo;</a>  
        <?php endif; ?>

        <?php if (isset($this->previous) && ($this->previous != $this->current) ): ?>
            <a href="<?= $this->url(array('page' => $this->previous),$this->route); ?>">&laquo;</a>
        <?php endif; ?>
        
        <?php foreach ($this->pagesInRange as $page): ?>
            <?php if ($page != $this->current): ?>
                <a href="<?= $this->url(array('page' => $page)); ?>"><?= $page; ?></a>
            <?php else: ?>
                <span id='current'><?php echo $page; ?></span>
            <?php endif; ?>
        <?php endforeach; ?>
        
        <!-- Next page link -->
        <?php if (isset($this->next) && ($this->next != $this->current) ): ?>
            <a href="<?php echo $this->url(array('page' => $this->next)); ?>">&raquo;</a>
        <?php endif; ?>
        
        <!-- Last page link -->
        <?php if (isset($this->last) && ($this->last != $this->current) ): ?>
          <a href="<?= $this->url(array('page' => $this->last),$this->route); ?>">&raquo;&raquo;</a> 
        <?php endif; ?>
        
    </div>
    
<?php endif; ?>


// css
/* Paginator */

#pagination {
    margin-top: 10px;
    text-align: right;
    font-size: 10px;
}

#pagination a{
    text-decoration: none;
    padding: 1px 8px 1px 8px;
    border: 1px solid;
    border-top: 0px;
    border-left: 0px;
    border-color: #cccccc;
    background: #eeeeee;
    color: #000000;
    margin-left: 2px;
}

#nextprev {
    /*background: #f7f7f7;*/
}

#current {
    text-decoration: none;
    padding: 1px 8px 1px 8px;
    border: 1px solid;
    border-right: 0px;
    border-bottom: 0px;
    border-color: #cccccc;
    background: #ffffff;
    margin-left: 5px;
}


http://framework.zend.com/manual/en/zend.paginator.usage.html
http://framework.zend.com/manual/en/zend.paginator.advanced.html