Skip to content

Instantly share code, notes, and snippets.

@maliMirkec
Last active August 29, 2015 14:21
Show Gist options
  • Save maliMirkec/8624b148f62f6e8477d6 to your computer and use it in GitHub Desktop.
Save maliMirkec/8624b148f62f6e8477d6 to your computer and use it in GitHub Desktop.
Phalcon Paginator with full URI
<?php
use Phalcon\Paginator\Adapter\Model;
use Phalcon\Http\Request;
class Paginator extends Phalcon\Paginator\Adapter\Model {
public function getPaginate($page_param = false) {
if(!$page_param) {
$page_param = "page";
}
$paginate = parent::getPaginate();
$request = new Request();
$uri = $request->getURI();
$separator = (strpos($uri, "?") !== false) ? "&$page_param=" : "?$page_param=";
$pos = strrpos($uri, "$page_param=");
if($pos !== false) {
$uri = substr($uri, 0, $pos - 1);
}
$before = ($paginate->current !== $paginate->first) ? $paginate->current - 1 : false;
$next = ($paginate->current !== $paginate->last) ? $paginate->current + 1 : false;
$paginate->before = ($before !== false) ? $uri.$separator.$before : "#";
$paginate->next = ($next !== false) ? $uri.$separator.$next : "#";
$paginate->first = ($paginate->first !== $paginate->current) ? $uri.$separator.$paginate->first : "#";
$paginate->last = ($paginate->last !== $paginate->current) ? $uri.$separator.$paginate->last : "#";
return $paginate;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment