Kostache-pagination-helper is a project mainly written in PHP, based on the MIT license.
Pagination Helper for KOstache (Kohana 3.1.x module)
This module might save you some time adding pagination to your application, that use KOstache.
You'll be able to easily add pagination to your views (including multiple independent paginations) and change pagination styles across your application as simple as changing a config parameter.
In your template:
...
{{#pagination}}{{>pagination}}{{/pagination}}
...
In your view file:
public function __construct($template = NULL, array $partials = NULL)
{
parent::__construct($template, $partials);
// Create pagination instance
$this->pagination = Kostache_Pagination::factory(array(
'kostache' => $this,
'items_per_page' => 50,
'partial' => 'pagination',
'view' => 'pagination/basic',
));
}
Notes:
kostache
(optional) is an instance of Kostache
class, i.e. your view model.partial
(optional, although if you set one of these, you should also set the other, otherwise it makes no sense)
is the name of partial you use in your template file, e.g. you can pass 'pagination'
, if you have {{>pagination}}
in your template.
That will also be the name of your view method (see below).view
parameter to 'pagination/basic'
, as it is Pagination default value.View file continued:
public function pagination()
{
$this->pagination->total_items = $this->_get_data_count();
return $this->pagination->render();
}
Notes:
pagination()
method, you need the
following section in the template: {{#pagination}}{{> ... }}{{/pagination}}
. The partial name doesn't have to match the section name.total_items
property of pagination and call render()
method. It doesn't actually render view to a string,
but rather returns an array to your view, for use in the appropriate template partial.$this->_get_data_count()
with your own method call, that returns items count.pagination
method.If you don't like setting total_items
after creating pagination instance, since it, well, may not be "correct" way to do so, you can
also create and return its instance in pagination()
method:
public function pagination()
{
return Kostache_Pagination::factory(array(
'items_per_page' => 50,
'total_items' => $this->_get_data_count(),
'view' => 'pagination/punbb',
))->render();
}
But in this case, you'd need to manually add partial, because it's too late to do so at this point. For example:
public function __construct($template = NULL, array $partials = NULL)
{
$this->_partials['pagination'] = 'pagination/punbb';
parent::__construct($template, $partials);
}
Note, that in this example pagination uses another pagination style (punbb), that I've ported from Kohana 2.
At the moment, the following views are supported out of the box:
pagination/basic
(default) - basic pagination:
First Previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14 Next Last
pagination/punbb
- pagination like in PunBB (ported from Kohana 2.3.x pagination module):
Displayed 31-60 of 150
Pages: 1 … 4 5 6 7 8 … 15