Overview

Packages

  • Pinoco
    • PAL

Classes

  • Pinoco
  • Pinoco_Delegate
  • Pinoco_DynamicVars
  • Pinoco_HttpRequestVars
  • Pinoco_List
  • Pinoco_MIMEType
  • Pinoco_NativeRenderer
  • Pinoco_NothingVars
  • Pinoco_NullRenderer
  • Pinoco_OptionalParam
  • Pinoco_Pagination
  • Pinoco_PDOStatementWrapper
  • Pinoco_PDOWrapper
  • Pinoco_Renderer
  • Pinoco_Router
  • Pinoco_TALRenderer
  • Pinoco_TestEnvironment
  • Pinoco_Validator
  • Pinoco_ValidatorContext
  • Pinoco_Vars

Interfaces

  • Pinoco_ArrayConvertible

Functions

  • __pinoco_autoload_impl
  • Overview
  • Package
  • Class
  • Tree

Class Pinoco_Pagination

Pagination object designed for PHPTAL. This object is independent from RDBMS. You can use it with any data source.

$pagination = new Pinoco_Pagination(
    // How many elements?
    function($pagination) {
        return $pagination->db->prepare(
            "SELECT count(id) as c FROM ..."
        )->query()->fetchOne()->c;
    },
    // What to be shown?
    function($pagination, $offset, $limit) {
        return $pagination->db->prepare(
            "SELECT * FROM ... LIMIT $offset, $limit"
        )->query()->fetchAll();
    },
    // How the page number is formatted in navigation?
    function($pagination, $page) {
        return 'list' . ($page > 1 ? '?page=' . $page : '');
    },
    array(
        'elementsPerPage' => 20,
        'db' => $db, // you can pass any custom property to pagination.
    )
);
$pagination->page = 1;
if (!$pagination->isValidPage) { $this->notfound(); }

PHPTAL example

<tal:block tal:repeat="element pagination/data">
   ${element/prop}
</tal:block>
<div class="pagination"
    tal:define="prev pagination/prev; pages pagination/pages; next pagination/next">
    <!--! prev button -->
    <a href="" tal:condition="prev/enabled"
       tal:attributes="href url:${prev/href}">PREV</a>
    <span class="disabled" tal:condition="not:prev/enabled">PREV</span>
    <!--! page link buttons -->
    <tal:block tal:repeat="page pages">
        <tal:block tal:condition="not:page/padding">
            <a href="" tal:condition="not:page/current"
               tal:attributes="href url:${page/href}"
               tal:content="page/number">1</a>
            <span class="current" tal:condition="page/current"
               tal:content="page/number">1</span>
        </tal:block>
        <span tal:condition="page/padding">...</span>
    </tal:block>
    <!--! next button -->
    <a href="" tal:condition="next/enabled"
       tal:attributes="href url:${next/href}">NEXT</a>
    <span class="disabled" tal:condition="not:next/enabled">NEXT</span>
</div>
Pinoco_Vars implements IteratorAggregate, ArrayAccess, Countable, Pinoco_ArrayConvertible
Extended by Pinoco_DynamicVars
Extended by Pinoco_Pagination
Package: Pinoco
Copyright: Copyright 2010-2012, Hisateru Tanaka <tanakahisateru@gmail.com>
License: License (http://www.opensource.org/licenses/mit-license.php)
Author: Hisateru Tanaka <tanakahisateru@gmail.com>
Located at Pinoco/Pagination.php
Methods summary
public
# __construct( callable $totalCountCallable, callable $dataFetchCallable, callable $urlFormatCallable, array $options = array() )

Creates pagination object from user codes.

Creates pagination object from user codes.

Parameters

$totalCountCallable
callable
$totalCountCallable
$dataFetchCallable
callable
$dataFetchCallable
$urlFormatCallable
callable
$urlFormatCallable
$options
array
$options

Overrides

Pinoco_Vars::__construct()
public
# get_page( )
public
# set_page( mixed $value )
public
# get_isValidPage( )
public
# get_elementsPerPage( )
public
# set_elementsPerPage( mixed $value )
public
# get_pagesAfterFirst( )
public
# set_pagesAfterFirst( mixed $value )
public
# get_pagesAroundCurrent( )
public
# set_pagesAroundCurrent( mixed $value )
public
# get_pagesBeforeLast( )
public
# set_pagesBeforeLast( mixed $value )
public integer
# get_totalCount( )

Total number of elements.

Total number of elements.

Returns

integer
public mixed
# get_data( )

Elements in paginated range. The fetched result is cached before changing current page.

Elements in paginated range. The fetched result is cached before changing current page.

Returns

mixed
public
# reset( )

Force to clear cached data.

Force to clear cached data.

public integer
# get_totalPages( )

Total number of pages.

Total number of pages.

Returns

integer
public Pinoco_List
# get_pages( )

Navigation information of each page buttons.

Navigation information of each page buttons.

Returns

Pinoco_List
public Pinoco_Vars
# get_prev( )

Navigation information of the prev button.

Navigation information of the prev button.

Returns

Pinoco_Vars
public Pinoco_Vars
# get_next( )

Navigation information of the next button.

Navigation information of the next button.

Returns

Pinoco_Vars
Methods inherited from Pinoco_DynamicVars
get(), getIterator(), has(), keys(), set()
Methods inherited from Pinoco_Vars
__call(), __get(), __isset(), __set(), __toString(), __unset(), count(), fromArray(), import(), markAsDirty(), offsetExists(), offsetGet(), offsetSet(), offsetUnset(), registerAsDynamic(), registerAsLazy(), registerAsMethod(), remove(), rget(), setDefault(), setLoose(), toArray(), toArrayRecurse(), values(), wrap()
Magic properties summary
public integer $page
#

The page number that starts with 1. (not 0!)

The page number that starts with 1. (not 0!)

public integer $elementsPerPage
#

Amount of data shown in single page.

Amount of data shown in single page.

public integer $pagesAfterFirst
#

How many buttons after the first page. (-1: hides first page)

How many buttons after the first page. (-1: hides first page)

public integer $pagesAroundCurrent
#

How many buttons around current page. (-1: expand all pages)

How many buttons around current page. (-1: expand all pages)

public integer $pagesBeforeLast
#

How many buttons before the last page. (-1: hides last page)

How many buttons before the last page. (-1: hides last page)

public read-only integer $totalCount
#

Total number of elements.

Total number of elements.

public read-only integer $totalPages
#

Total number of pages.

Total number of pages.

public read-only mixed $data
#

Elements in paginated range.

Elements in paginated range.

public read-only Pinoco_List $pages
#

Navigation information of each page buttons.

Navigation information of each page buttons.

public read-only Pinoco_Vars $prev
#

Navigation information of the prev button.

Navigation information of the prev button.

public read-only Pinoco_Vars $next
#

Navigation information of the prev button.

Navigation information of the prev button.

Pinoco 0.8.0 Documentation API documentation generated by ApiGen 2.8.0