CodeIgniter Forums
Pagination from library causing problem, help needed. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Pagination from library causing problem, help needed. (/showthread.php?tid=7563)



Pagination from library causing problem, help needed. - El Forum - 04-14-2008

[eluser]geshan[/eluser]
I'm working on a library which needs pagination the code for the generation of pagination link is as follows (it is in the library):

Code:
function paginate($page_size){
        
            $ts=$this->CI->uri->total_segments();//for getting last uri segment
        
         $config['uri_segment'] = $this->CI->uri->segment($ts);
         $config['base_url'] = $this->base_url; //has  http://localhost/myapp/index.php/mycontroller/show_tbl/
         $config['total_rows'] = $this->total_rows; //has 23
        
         $config['per_page'] = $page_size; //has 5
         $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_ret=$this->CI->pagination->create_links();
        $this->paging_links=$paging_links_ret;
        return $paging_links_ret;
    }//function paginate close

Now the problem is:

The next link always goes to http://localhost/myapp/index.php/mycontroller/show_tbl/5 which ever the current page is like if I click next from http://localhost/myapp/index.php/mycontroller/show_tbl/15 (page 4)it goes to 2nd page i.e, base_url/5 and page 1 has no link in any case.

There are no previous or first link thought I'm at page x (any page). I'm not getting what is the problem and what am I doing wrong. This same function seem to work in a controller but its not working here. Please help.


Pagination from library causing problem, help needed. - El Forum - 07-11-2008

[eluser]extra_rice[/eluser]
same problem here... did you solve it by any chance?


Pagination from library causing problem, help needed. - El Forum - 07-11-2008

[eluser]hvalente13[/eluser]
Hi,

I think that you problem is at the config param of the uri segment.

Try to give it a fixed number ($this->uri->segment(4) - 4 is just an example).

I guess that this:

Quote:http://localhost/myapp/index.php/mycontroller/show_tbl/5

Code:
$ts=$this->CI->uri->total_segments();//for getting last uri segment

gives you the total number of uri segments, in this case = 6, but you want the 3rd.

Hope this helps.