Welcome Guest, Not a member yet? Register   Sign In
Pagination in library file return blank result
#1

[eluser]geshan[/eluser]
I'm working on a library for something I want to paginiate the results of a SQL query.

I've loaded he pagination library in the constructor of the library.
Code:
$this->CI->load->library('pagination');

//and other needed variables

$this->controller = $this->CI->uri->segment(1);
// Set the base URL
$this->base_url = $this->CI->config->site_url().'/'.$this->CI->uri->segment(1).$this->CI->uri->slash_segment(2, 'both');

//assume total_rows also has value say 10 and query is running OK.

I just need a function to get the pagination links that I can send to the controller as an array element like

Code:
$query_res['paging_links']=paginate(5); //5 is per page results

The paginate function that return me nothing is:

Code:
function paginate($page_size){
        
        //LIMIT ".$offset.",".$perpage);
         $config['uri_segment'] = 4; //$this->CI->URI->total_segments();
         $config['base_url'] = $this->base_url;
         $config['total_rows'] = $this->total_rows;
         $config['per_page'] = $page_size;
         $config['num_links'] = 5;
    
         $config['full_tag_open'] = '<div id="pagination">';
         $config['full_tag_close'] = '</div>';
    
    
         $config['first_link'] = '<< Start';
         $config['last_link'] = 'End >>';
         $config['next_link'] = 'Next >';
         $config['prev_link'] = '< Prev';
    
         $this->CI->pagination->initialize($config);
        
        $paging_links=$this->CI->pagination->create_links();
        echo "<br><br>Paging links in paginate has: ".$paging_links;
        return $paging_links;
    }//function paginate close

Above paginate function used to work ok in a controller, Whats wrong with the above code, please help...
#2

[eluser]Seppo[/eluser]
$this->CI ?
Probably you need to use
Code:
$CI =& get_instance();
$CI->pagination->initialize($config);
// ............
instead...

Also, It is recommended to enable display_errors on development to find out the errors faster... you can simple ini_set('display_errors', 'On');




Theme © iAndrew 2016 - Forum software by © MyBB