Arraypager

I have build an extension for Yii that allows you to paginate an array.

If you have an array of data and you want a simple pager for it, then the

ArrayPagger is te best solution.

ArrayPager features:

  1. Calculate pages count based on items per page;

  2. Generate pages links;

  3. Get page data;

  4. Paginator setting;

Install:

just copy the ArrayPager folder from archive to


yiipath/application/protected/extensions

Usage:





// In your controller let's say arraytest and action results  

// You have an array of any type of data

    $search_results = array(1 => "texts", 2 => "arrays", 3 => "objects", 4 => "xmls", 5 => "numbers", 6 => "any kind of data", 7 => "json data");

	

	// import ArrayPager class or load it in main config file 

 	Yii::import('application.extensions.ArrayPager.ArrayPager');

	

	// Create new array pagination object and passing the parameters

	$pagination = new ArrayPager($search_results, 'arraytest/results', array(

			'currentPage' 		=> (array_key_exists('page',$_GET) ? $_GET['page'] : 1),

			'perPage' 		=> 10,

			'linksClass' 		=> 'pagination-page-link',

			'selectedLinkClass'     => 'pagination-page-link-selected',

			'nextPageLinkText' 	=> '<img src="'.Yii::app()->baseUrl.'/images/arrow-right.png">',

			'prevPageLinkText' 	=> '<img src="'.Yii::app()->baseUrl.'/images/arrow-left.png">',

			'showPrevAndNext'	=> true,

			'showFirstAndLast'	=> true,

			'maxButtonsCount'	=> 4 // to show all links set this to 0

	));

	

	$page_results = $pagination->getResults();

	$pagination_links = '<div class="pagination">'.$pagination->getLinks().'</div>';

        $this->render('results',array('page_results'=>$page_results,'pagination_links'=>$pagination_links));








// in your view file


// loop from results

foreach( $page_results as $result){

   echo $result;

}


// render pagination links

echo $pagination_links;