Skip to content

Pagination

inghamn edited this page Sep 13, 2012 · 1 revision

Pagination

We use the List classes to collect the results from the database. These List classes extend the ZendDbResultIterator which handles actually executing the query. The ZendDbResultIterator also handles pagination by rewriting the query as necessary.

Looking up data typically flows like this:

<?php
$list = new SomethingList(array('field'=>'value'));
foreach ($list as $something) { // $something is a Something object
    echo $something->getId();
}

The query isn't actually executed until the first attempt to use the data. In addition, turning on Pagination will reset the results from query. This leads to the query executing again on the next use of the data.

<?php
$list = new SomethingList();
$list->find();                  // prepares "select * from something"
foreach ($list as $something) { // executes "select * from something and loads all results
    echo $something->getId();
}

If we want to do pagination, we can turn it on anytime, but it's most effecient to make sure to turn it on before reading from the List.

Effecient

<?php
$list = new SomethingList();
$list->find();                      // query prepared
$list->setPagination(10, 1);        // query rewritten
if (count($list)) {                 // query executed and 10 results loaded
    foreach ($list as $something) {
        echo $something->getId();
    }
}

Ineffecient

<?php
$list = new SomethingList();
$list->find();                      // query prepared
if (count($list)) {                 // query executed and all results loaded into memory
    $list->setPagination(10, 1);    // results thrown away and query rewritten
    foreach ($list as $something) { // query executed again and smaller results loaded
        echo $something->getId();
    }
}

Developer Guide

Features

Principles

  • Coding Style
  • Accessibility (Section 508)
  • Progressive Enhancement
  • Unobtrusive Javascript
Clone this wiki locally