Skip to content
inghamn edited this page Dec 10, 2014 · 3 revisions

We use the Table classes to collect the results from the database. These Table classes are implementations of the ZF2 TableGateway which handles actually executing the query. The base TableGateway also handles returing a ZF2 Paginator or the raw collection, based on a flag used in the ->find() methods.

Looking up data typically flows like this:

<?php
$table = new SomethingTable();
$list = $table->find(['field'=>'value']);
foreach ($list as $something) { // $something is a Something object
    echo $something->getId();
}

If we want to do pagination, we can tell the find method to do pagination. The table will return a Paginator object with only one page of results.

<?php
$table = new SomethingTable();
$list = $table->find(['field'=>'value'], null, true); // Third parameter is the pagination flag

$page = !empty($_GET['page']) ? (int)$_GET['page'] : 1;
$list->setCurrentPageNumber($page);
$list->setItemCountPerPage(20);
if (count($list)) {
    foreach ($list as $something) {
        echo $something->getId();
    }
}

Developer Guide

Features

Principles

  • Coding Style
  • Accessibility (Section 508)
  • Progressive Enhancement
  • Unobtrusive Javascript

Tutorials

Clone this wiki locally