CodeIgniter Forums
Pagination current URL. - 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 current URL. (/showthread.php?tid=34907)



Pagination current URL. - El Forum - 10-13-2010

[eluser]sahanlak[/eluser]
This is the config code for the pagination.
Code:
$this->load->library('pagination');

            $config['base_url']="http://domain.net/index.php/admin/partner/$ID/";
            $config['total_rows']=5;
            $config['per_page']=2;
            $config['num_links']=20;
            $config['cur_tag_open'] = '<b>';
            $config['cur_tag_close'] = '</b>';


        $this->pagination->initialize($config);

$ID is an integer. The problem is pagination wont select the current page, its always selecting the number 1.

Why is that?


Pagination current URL. - El Forum - 10-13-2010

[eluser]Thomas Edwards[/eluser]
You need this:
Code:
$config['uri_segment'] = 3;
And you need to take the $ID out.
Code:
$config['base_url']="http://domain.net/index.php/admin/partner/";

Pagination Class


Pagination current URL. - El Forum - 10-13-2010

[eluser]sahanlak[/eluser]
Actually after page get viewed in the browser, the base url is like this. http://domain.net/index.php/admin/partner/1/

So with paginated
http://domain.net/index.php/admin/partner/1/2


Pagination current URL. - El Forum - 10-13-2010

[eluser]sahanlak[/eluser]
It dsnt work, even if I set it correctly in $config['uri_segment'] its capturing the "1" in here
http://domain.net/index.php/admin/partner/1/2
but it has to be 2 the last number of the url.


Pagination current URL. - El Forum - 10-13-2010

[eluser]Thomas Edwards[/eluser]
Like I said, you need to take the variable out of the base_url.

Code:
$this->load->library('pagination');

$config['base_url'] = "http://domain.net/index.php/admin/partner/";
$config['total_rows'] = 5;
$config['per_page'] = 2;
$config['num_links'] = 20;
$config['uri_segment'] = 3;
$config['cur_tag_open'] = '<b>';
$config['cur_tag_close'] = '</b>';

$this->pagination->initialize($config);



Pagination current URL. - El Forum - 10-13-2010

[eluser]Thomas Edwards[/eluser]
Here’s a page: http://www.unionplus.co.uk/test/pages/

Here’s the code:
Code:
function pages()
{
$this->load->library('pagination');

$config['base_url'] = "/test/pages/";
$config['total_rows'] = 5;
$config['per_page'] = 2;
$config['num_links'] = 20;
$config['uri_segment'] = 3;

$this->pagination->initialize($config);

echo $this->pagination->create_links();
}



Pagination current URL. - El Forum - 10-13-2010

[eluser]sahanlak[/eluser]
Yea that works, but I think the pagination get confuced with my url structure.

http://domain.net/index.php/admin/partner/1/2/

lets take number 1 and 2, number one is an input var that I pass to the partner method in admin controller; 2 is the number for pagination but for some reason even if I specify $config['uri_segment'] = 4; it keeps getting the 1 instead of 2. Hope it make sense.


Pagination current URL. - El Forum - 10-13-2010

[eluser]sahanlak[/eluser]
For your example its not necessary to specify $config[‘uri_segment’] I think