public function pagination()
{
return _class('html')->pagination([
'1' => url('/some/action/1'),
'2' => url('/some/action/2'),
'prev' => url('/some/action/1'),
'next' => url('/some/action/2'),
'3' => url('/some/action/3'),
'4' => url('/some/action/4'),
'5' => url('/some/action/5'),
]);
}
public function pagination($data = [], $extra = [])
{
$extra['id'] = $extra['id'] ?: __FUNCTION__ . '_' . ++$this->_ids[__FUNCTION__];
if (isset($data['prev'])) {
$prev = $data['prev'];
unset($data['prev']);
}
if (isset($data['next'])) {
$next = $data['next'];
unset($data['next']);
}
$items = [];
// TODO: auto-detect current page and need of first. last
if ($prev) {
$items[] = '<li><a href="' . $prev . '">' . t('Prev') . '</a></li>';
}
foreach ((array) $data as $page => $link) {
$items[] = '<li><a href="' . $link . '">' . $page . '</a></li>';
}
if ($next) {
$items[] = '<li><a href="' . $next . '">' . t('Next') . '</a></li>';
}
if ($this->_is_bs3) {
return '<div><ul class="pagination' . ($extra['class'] ? ' ' . $extra['class'] : '') . '" id="' . $extra['id'] . '">' . implode(PHP_EOL, $items) . '</ul></div>';
}
return '<div class="pagination' . ($extra['class'] ? ' ' . $extra['class'] : '') . '" id="' . $extra['id'] . '"><ul>' . implode(PHP_EOL, $items) . '</ul></div>';
}