From acc279989cfc2872abd92586caa4f98ba07d30cb Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 21 Jul 2011 07:26:24 -0700 Subject: [PATCH] Move last page logic into Paginator class. --- system/paginator.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/system/paginator.php b/system/paginator.php index 9388dcc5..1080e0ec 100644 --- a/system/paginator.php +++ b/system/paginator.php @@ -47,11 +47,11 @@ class Paginator { */ public function __construct($results, $total, $per_page) { + $this->page = static::page($total, $per_page); + $this->per_page = $per_page; $this->results = $results; $this->total = $total; - - $this->page = static::page($this->last_page()); } /** @@ -60,11 +60,14 @@ class Paginator { * The page will be validated and adjusted if it is less than 1 or * greater than the last page number. * - * @param int $last_page + * @param int $total + * @param int $per_page * @return int */ - public static function page($last_page) + public static function page($total, $per_page) { + $last_page = ceil($total / $per_page); + $page = Input::get('page', 1); if (is_numeric($page) and $page > $last_page)