Giter Club home page Giter Club logo

paginator's Introduction

Paginator

Build Status Scrutinizer Code Quality SensioLabsInsight

Installation

$ php composer.phar require 'anh/paginator:0.2.*'

Usage

Create paginator and call it's paginate() method with data, page number and number of elements per page. It will find appropriate adapter and return Page instance, filled with paginated data, it can be used in foreach directly. Also you can pass manually created adapter instead of data.

<?php

use Anh\Paginator\Paginator;

$query = /* ORM Query or QueryBuilder for fetching users */;

$paginator = new Paginator();
$users = $paginator->paginate($query, 1, 10);

foreach ($users as $user) {
    // do something with user
}

If you need to pass options to adapter, pass it to paginate() as fourth parameter. Note each adapter has own options.

<?php

use Anh\Paginator\Paginator;
use Anh\Paginator\Adapter\ArrayAdapter;

$data = array(/* elements */);

$paginator = new Paginator();
$elements = $paginator->paginate($data, 3, 20, array('preserveKeys' => true));

foreach ($elements as $key => $element) {
    // do something with element
}

You can create custom adapters and add them to AdapterResolver. All adapters must implement AdapterInterface interface.

<?php

use Anh\Paginator\Paginator;
use Anh\Paginator\AdapterResolver;

$adapterResolver = new AdapterResolver();
$adapterResolver->addAdapter('Some\Custom\Adapter1');
$adapterResolver->addAdapter('Some\Custom\Adapter2');

$paginator = new Paginator($adapterResolver);
$elements = $paginator->paginate($data, $pageNumber, $elementsPerPage);

foreach ($elements as $element) {
    // do something with element
}

Rendering

<?php

use Anh\Paginator\Paginator;
use Anh\Paginator\View\AdaptiveView;

$paginator = new Paginator();
$posts = $paginator->paginate(/* ... */);

$view = new AdaptiveView();
$view->setTemplates(array(/* templates */));
$view->setOptions(array(/* options */));

echo $view->render($posts, '/some/url/page-%page%', array(/* options */));

For complete list of templates and options see sources. Also you can use resource/pagination.css for paginator styling. It is based on pagination from foundation zurb.

Available adapters

  • EmptyDataAdapter
  • ArrayAdapter
  • DoctrineOrmAdapter

Versioning

Library uses semantic versioning.

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.