Güzel bir sayfalama sınıfı, kullandığımız dil php dir.Konu başlığından anlaşılacağı gibi basit bir sayfalama sınıfı, sınıfın olduğu kod aşağıda onun hemen aldında da kullanımı olan kod parçası vardır.
/** * pagination * * @package pagination * @author can acar * @copyright 2010 * @version 1 * @access public */ class pagination { static private $total; static private $limit; static private $obj; static private $pages; static private $get_page; static private $start; static private $showFirstAndLast; /** * pagination::set() * * @param mixed $args Array object * @param integer $limit limit * @param integer $page current page int value * @return */ public static function set($args, $limit = 10, $page ) { self::$obj = $args; self::$limit = $limit; self::$get_page = (empty($page))?1:$page; self::$total = count($args); self::$pages = ceil(self::$total / self::$limit); self::$start = ceil(intval(self::$get_page - 1) * self::$limit); } /** * pagination::fetchperpage() * * @return */ public static function fetchperpage() { if (is_array(self::$obj)) { $o = array_slice(self::$obj, self::$start, self::$limit); } else { $o = array(null); } return $o; } /** * pagination::navigation() * * @return */ public static function navigation() { $plinks = array(); $links = array(); $slinks = array(); if (count($_GET)) { $i = strripos($_SERVER["REQUEST_URI"], '?'); $queryURL = substr($_SERVER["REQUEST_URI"], 0, $i + 1); foreach ($_GET as $key => $value) { if ($key != 'pagenum') { $sp = (empty($value)) ? " " : "=" . $value; $queryURL .= '&' . $key . "=" . $value; } } } if ((self::$pages) > 1) { if (self::$get_page > 1) { $plinks[] = '<a href=' . $queryURL . '&pagenum=' . (self::$get_page - 1) .'>«</a>'; } else { $slinks[] = '<a href="' . $queryURL . '&pagenum=' . self::$pages .'">Last</a>'; } for ($j = 1; $j <= (self::$pages); $j++) { if (self::$get_page == $j) { $links[] = ' <span class="page-numbers current">' . $j . '</span>'; } else { $links[] = ' <a href=' . $queryURL . '&pagenum=' . $j . ' class="page-numbers">' . $j . '</a> '; } } if (self::$get_page < self::$pages) { $slinks[] = ' <a href=' . $queryURL . '&pagenum=' . (self::$get_page + 1) . ' > » </a>'; } else { $plinks[] = ' <a href="' . $queryURL . '&pagenum=0">First</a>'; } return implode(' ', $plinks) . implode(' ', $links) . implode(' ', $slinks); } return; } } ?>
Php ile yazılmış sayfalama sınıfınının kullanımıda şöyledir:
$array = Array('A'=>1,'B'=>2,'C'=>3,'D'=>4,'E'=>5); // array dizisi $i = $_GET['pagenum']; Pagination::set($array, 3, $i); // 3 limit değeri echo Pagination::navigation(); // navigation menüsü , listenin başında yada altında durabilir.. echo "<br>"; foreach (Pagination::fetchperpage() as $key=>$value): echo $key.'=>'.$value.'<br>'; endforeach;
Yazılan sınıf ceviz forumdan alıntıdır.
Responses to “php basit sayfalama sınıfı”