From: Christian Weiske Date: Thu, 3 May 2012 05:50:02 +0000 (+0200) Subject: search paging X-Git-Tag: v0.2.0~28 X-Git-Url: https://git.cweiske.de/phorkie.git/commitdiff_plain/f54be9a638c1f0d8f6a04bc2e0b8e0eb0731a720?ds=sidebyside search paging --- diff --git a/data/templates/search.htm b/data/templates/search.htm index 51bf982..39350c0 100644 --- a/data/templates/search.htm +++ b/data/templates/search.htm @@ -15,6 +15,7 @@ {% include 'repo-list.htm' %} {% endfor %} + {{pager.getLinks.all|raw}} {% endif %} {% endblock %} diff --git a/src/phorkie/Search/Result.php b/src/phorkie/Search/Result.php index e64a3a6..00bb1ec 100644 --- a/src/phorkie/Search/Result.php +++ b/src/phorkie/Search/Result.php @@ -42,6 +42,11 @@ class Search_Result { return $this->perPage; } + + public function getLink($query) + { + return '/search?q=' . urlencode($query); + } } ?> diff --git a/www/search.php b/www/search.php index aef209f..9461b0d 100644 --- a/www/search.php +++ b/www/search.php @@ -16,7 +16,8 @@ if (isset($_GET['page'])) { if (!is_numeric($_GET['page'])) { throw new Exception_Input('List page is not numeric'); } - $page = (int)$_GET['page']; + //PEAR Pager begins at 1 + $page = (int)$_GET['page'] - 1; } $perPage = 10; @@ -24,11 +25,28 @@ $db = new Database(); $search = $db->getSearch(); $sres = $search->search($query, $page, $perPage); + +//fix non-static factory method error +error_reporting(error_reporting() & ~E_STRICT); +$pager = \Pager::factory( + array( + 'mode' => 'Sliding', + 'perPage' => 10, + 'delta' => 2, + 'totalItems' => $sres->getResults(), + 'currentPage' => $page + 1, + 'urlVar' => 'page', + 'path' => '/', + 'fileName' => $sres->getLink($query), + ) +); + render( 'search', array( 'query' => $query, 'sres' => $sres, + 'pager' => $pager ) ); ?>