2017 © Pedro Peláez
 

library slim-pagination

simple pagination for slim3

image

xandros15/slim-pagination

simple pagination for slim3

  • Tuesday, July 12, 2016
  • by xandros15
  • Repository
  • 4 Watchers
  • 8 Stars
  • 223 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 5 Forks
  • 1 Open issues
  • 6 Versions
  • 10 % Grown

The README.md

SlimPagination

simple pagination for slim3, (*1)

Requirements

PHP 7.0 or higher, (*2)

Slim 3.0, (*3)

Installation

via composer: composer require xandros15/slim-pagination, (*4)

Basic Usage

Create a object of pagination inside of controller callback, fetch it into string via renderer and pass it as variable:, (*5)

get('/users', function (Request $request, Response $response) {
 $users = User::search($request);
 $pagination = new Pagination($request, $this->get('router'),[
                Pagination::OPT_TOTAL => count($users), //number of items
            ]);
 $paginationString = $this-view->fetch('pagination', ['pagination' => $pagination]);
 return $this->view->render('user.index', ['pagination' => $paginationString]);
 })->name('user.index');

```

Them render if via template manager.

### PHP template example
```php

Twig template example

{% if pagination.canCreate %}
    <nav class="text-center col-xs-12">
        <ul class="pagination">
            {% if pagination.previous.isCurrent %}
                <li class="disabled">
                    <span>{{ pagination.previous.pageName | raw }}</span>
                </li>
            {% else %}
                <li>
                    <a aria-label="previous" href="{{ pagination.previous.pathFor }}">
                        <span aria-hidden="true">{{ pagination.previous.pageName | raw }}</span>
                    </a>
                </li>
            {% endif %}
            {% for page in pagination %}
                {% if page.isSlider %}
                    <li class="disabled"><span>{{ page.pageName }}</span></li>
                {% elseif page.isCurrent %}
                    <li class="active"><span>{{ page.pageName }}</span></li>
                {% else %}
                    <li><a href="{{ page.pathFor}}">{{ page.pageName }}</a></li>
                {% endif %}
            {% endfor %}
            {% if pagination.next.isCurrent %}
                <li class="disabled">
                    <span aria-hidden="true">{{ pagination.next.pageName | raw }}</span>
                </li>
            {% else %}
                <li>
                    <a aria-label="next" href="{{ pagination.next.pathFor }}">
                        <span aria-hidden="true">{{ pagination.next.pageName | raw }}</span>
                    </a>
                </li>
            {% endif %}
        </ul>
    </nav>
{% endif %}

Options

Name Info Default More
Pagination::OPT_TOTAL set to total of items (int) 1 -
Pagination::OPT_PARAM_NAME set param name (string) page ?page=2 or route /[{page:\d+}] has param name: page
Pagination::OPT_PARAM_TYPE set param type (e.g via query or attribute) PageList::PAGE_QUERY PageList::PAGE_QUERY for: ?page=2
PageList::PAGE_ATTRIBUTE for: /page/2
Pagination::OPT_PER_PAGE set how many items should be show on one page (int) 10 -
Pagination::OPT_SIDE_LENGTH set how many buttons should be show before slider (int) 3 -
Pagination::OPT_LIST_TYPE set type of list PageList::NORMAL available:
PageList::NORMAL;
PageList::MINI
PageList::NONE

PageList Type:

PageList::NORMAL is normal pagination with slider:, (*6)

normal, (*7)

PageList::MINI is minimalistic pagination:, (*8)

mini, (*9)

can be created by simple code:, (*10)

twig

{% for page in pagination %}
    {% if page.isCurrent %}
        <li class="disabled"><span>{{ page.pageName }}</span></li>
    {% else %}
        <li><a href="{{ page.pathFor }}">{{ page.pageName }}</a></li>
    {% endif %}
{% endfor %}

php

<?php foreach ($pagination as $page): ?>
    <?php if ($page['isCurrent']): ?>
        <li class="disabled">
            <span><?= $page['pageName'] ?></span>
        </li>
    <?php else: ?>
        <li>
            <a href="<?= $page['pathFor'] ?>"><?= $page['pageName'] ?></a>
        </li>
    <?php endif; ?>
<?php endforeach; ?>

PageList::NONE turns off pagination, (*11)

Methods and Attributes

Page

pathFor - returning path for this page, (*12)

isCurrent - check if this page is current, (*13)

pageName - returning page name (e.g. number), (*14)

isSlider - check if this page is slider, (*15)

Pagination

previous() - getting previous page, if doesn't exist returning current, (*16)

next() - getting next page, if doesn't exist returning current, (*17)

first() - getting first page, (*18)

last() - getting last page, (*19)

canCreate() - checking if pagination can be create, (*20)

toArray() - returning array of defined params: * per_page: how many items on one page * current_page: number of current page * next_page_url: path for next page * prev_page_url: path for previous page * from: number of first item * to: number of last item, (*21)

toJson() - same as toArray(), just compile to json string, (*22)

The Versions

12/07 2016

dev-master

9999999-dev

simple pagination for slim3

  Sources   Download

MIT

The Requires

 

The Development Requires

by xandros

12/07 2016

0.1

0.1.0.0

simple pagination for slim3

  Sources   Download

MIT

The Requires

 

The Development Requires

by xandros

10/07 2016

0.0.2

0.0.2.0

simple pagination for slim3

  Sources   Download

MIT

The Requires

 

The Development Requires

by xandros

25/06 2016

0.0.1

0.0.1.0

simple pagination for slim3

  Sources   Download

MIT

The Requires

 

The Development Requires

by xandros

25/06 2016

dev-Assoc-Pages

dev-Assoc-Pages

simple pagination for slim3

  Sources   Download

MIT

The Requires

 

The Development Requires

by xandros

24/06 2016

dev-old-PageInterface

dev-old-PageInterface

simple pagination for slim3

  Sources   Download

MIT

The Requires

 

The Development Requires

by xandros