A
A
Andrew2016-01-07 00:08:42
Zend Framework
Andrew, 2016-01-07 00:08:42

How to make a pager in Zend Framework 1?

Hello, I'm trying to understand this framework, I need the first version. I am making a guest book for this series of articles ruseller.com/lessons.php?rub_id=37&id=989 with my minor edits (I display everything on the index page). It is necessary to implement a pager, I found something here framework.zend.com/manual/1.12/en/zend.paginator.u... but I still don't understand how to attach it to my case... It seems that I I did everything wrong from the very beginning. Please help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Cat Anton, 2016-01-07
@ntzch

The view now needs to pass a Zend_Paginator object (an array of paginated movies). I will give the simplest option, using Zend_Paginator_Adapter_Array. Once you're comfortable with it, you can rewrite it with an adapter that uses a database:

public function indexAction()
{
    $movies = new Application_Model_DbTable_Movies();
    $paginator = Zend_Paginator::factory($movies->fetchAll());
    $paginator->setItemCountPerPage(15);

    $page = $this->_getParam('page', 1);
    $paginator->setCurrentPageNumber($page);
    
    $this->view->movies = $paginator->getCurrentItems();
    $this->view->paginator = $paginator;
}

Add pagination output to the template:
<table>
    <tr>
        <th>Название</th>
        <th>Режиссёр</th>
        <th> </th>
    </tr>
    <?php echo $this->partialLoop('partials/movie.phtml', $this->movies); ?>
</table>
<?php echo $this->paginationControl($this->paginator, 'Sliding', 'pagination_control.phtml'); ?>

And the template for pagination itself. There are examples in the documentation:
framework.zend.com/manual/1.12/ru/zend.paginator.u...
There is no point in learning to write on ZF1 now. Soon ZF3 will be released.
An example of blog development on Zend Framework 2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question