Rene
Rene

Reputation: 642

Pagination in Zend Framework

I am a noob in Zend and I would appreciate if you could help me to figure out how to use pagination in my case.

this is my view and this is my controller

I am using APIs to access my models.

I researched and read a lot about pagination in Zend but I had/have trouble implementing it. Thank you for your willingness to help me out.

Upvotes: 2

Views: 3918

Answers (1)

redmoon7777
redmoon7777

Reputation: 4526

in your controller in line 36 write : (assuming $resultq is a valid zend_paginator param)

$paginator = Zend_Paginator::factory($resultq);      
$paginator->setCurrentPageNumber($this->getRequest()->getParam('page')); // page number
$paginator->setItemCountPerPage(20); // number of items to show per page

$this->view->paginator= $paginator;

now in your view you have to add pagination controls, either do it directly in the view or use a template (you can store templates in application/views/scripts/templates for example), here is an example of a pagination template : http://zendgeek.blogspot.com/2009/07/zend-pagination-example.html

then in your view you have to integrate the template (wherever you want the controls to appear) using:

 <?php echo $this->paginationControl($this->paginator, 'Sliding', 'templates/pagination.phtml'); ?>

and instead of using <?php foreach ($this->basicBwDetails as $result): ?> use <?php foreach ($this->paginator as $result): ?>

Upvotes: 2

Related Questions