Location: PHPKode > scripts > Menampilkan Halaman Pada framework > menampilkan-halaman-pada-framework/Class_halaman.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * CodeIgniter
 *
 * An open source application development framework for PHP 4.3.2 or newer
 *
 * @package		CodeIgniter
 * @author		Dwi Wahyudi
 * @copyright	Copyright (c) 2008, ICTConsulting.
 * @license		http://ictconsulting.web.id/
 * @link		http://ictconsulting.web.id/
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * Pagination Class
 *
 * @package		CodeIgniter
 * @subpackage	Libraries
 * @category	Pagination
 * @author		Dwi Wahyudi
 * @link		http://ictconsulting.web.id/
 */

class Class_halaman {
 
    var $url_halaman = '';
    var $bilangan_tampil = 0;
    var $halaman_awal = 0;
    var $halaman_banyak = 0;
    var $halaman_baris  = 0;
    
    var $tampilan_awal    ='<<';
    var $tampilan_akhir   ='>>';
    var $tampilan_sebelum ='<';
    var $tampilan_setelah ='>';
    
    
    function halaman_tampil($params = array())
    {
        	
    	
    	if (count($params) > 0)
		{
			foreach ($params as $key => $val)
			{
				if (isset($this->$key))
				{
					$this->$key = $val;
				}
			}		
		}
    	
    	
    	$start_tampil = $this->halaman_awal - ceil($this->bilangan_tampil/2);
    	$ulang = intval(ceil($this->halaman_banyak/$this->halaman_baris));
    	
    	if (($this->halaman_awal == 1) || ($start_tampil <= 1)){
    		$awal    = '';
    	    $sebelum = '';
    	}
    	else 
    	{
    	  $prior = $this->halaman_awal-1;
    	  $awal    = '<a href="'.$this->url_halaman.'/1">'.$this->tampilan_awal.'</a> ';
    	  $sebelum = '<a href="'.$this->url_halaman.'/'.$prior.'">'.$this->tampilan_sebelum.'</a> ';
    	}
    	
    	$nilai = intval($this->bilangan_tampil)+intval($start_tampil);
    	
    	if (($this->halaman_awal == $ulang)||($nilai >= $ulang))
    	{
    		$akhir   = '';    	
    	    $setelah = '';
    	   
    	}
    	else 
    	{
    	   $next  = $this->halaman_awal+1;
    	    
    	   $akhir   = ' <a href="'.$this->url_halaman.'/'.$ulang.'">'.$this->tampilan_akhir.'</a> ';    	
    	   $setelah = ' <a href="'.$this->url_halaman.'/'.$next.'">'.$this->tampilan_setelah.'</a> ';	
    	}
    	
    	
    	$halaman = $this->jumlah_tampil($start_tampil, $ulang);
    	$halaman = $awal.$sebelum.$halaman.$setelah.$akhir;
    	return $halaman;
    }
    
    function jumlah_tampil($start_tampil, $ulang)
    {
    	
    	$data = '';    	
    	$j = 1;
    	for ($i=1;$i<=$ulang;$i++)
    	{
    		
    		if (($j<=$this->bilangan_tampil) &&($i>=$start_tampil))
    		{
    		  if ($i == $this->halaman_awal)
    		  {
    			$data .= $i.' ';	
    		  }
    		  else 
    		  {
    		    $data .= '<a href="'.$this->url_halaman.'/'.$i.'">'.$i.'</a>'.' ';	
    		  }
    		  $j++;    		
    	    }
    	}    	
    	if ($j <= $this->bilangan_tampil)
    	{
    		$data = '...'.$data;
    	}
    	
    	if ($this->halaman_awal+$start_tampil < $ulang)
    	{
    		$data .= '...';
    	}
    
    	return $data;
    }
    
    
}

?>
Return current item: Menampilkan Halaman Pada framework