[eluser]raheelshan[/eluser]
This is my first ever post. And i have created a library that fits according to my requirements. It may help some one so i am posting it here. This may have some problems but with some restrictions its working fine or perhaps somebody can make it optimized and error free.
My Problem : The thing that gave my idea to create this library was that i wanted the user to have some options that how many results he wants to see while using pagination. To clearify let suppose i user have 4 options(links)
5 , 10 ,15 , 20
By default 5 is selected and pagination will show 5 records per page. On selecting 10 , 15 or 20 will regenerate the page numbers . Here is the code
Code:
Class My_Pagination extends Pagination
{
var $base_link = '';
var $per_page_link = TRUE;
var $per_page_array = array(); // parameters can be set
public function create_per_page()
{
$CI =& get_instance();
$output = '';
$current = $CI->uri->segment(3,5);
if($this->per_page_link === TRUE AND count($this->per_page_array) > 1){
foreach($this->per_page_array as $row){
if($current == $row){
$output .= $this->cur_tag_open . $row . $this->cur_tag_close;
$output .= ' ';
}else{
$output .= '<a href="'.$this->base_link.$row.'/1">'.$row.'</a>';
$output .= ' ';
}
}
}
return $output;
}
public function create_paged_links(){
//copy the whole code of create_links() in it and add these two lines after when you initialize ci instance
$this->per_page = $CI->uri->segment(3,5);
$this->uri_segment = $CI->uri->segment(4,1);
}
}