简体   繁体   中英

CodeIgniter Pagination Last Page Issue

I have been searching solution for my problem but i can't find an answer to it. My problem i believe is different than what normally others will be facing with codeigniter's pagination library.

I have 15 records inside my database and i wanna display 5 each page with the pagination. below is my pagination config :

    $config["base_url"] = base_url() . "main";
    $config["total_rows"] = $total_row[0]['total'];
    $config["per_page"] = 5;
    $config["uri_segment"] = $this->uri->segment(2);
    $config['num_links'] = 2;
    $config['use_page_numbers'] = TRUE;

    $config['cur_tag_open'] = '<b>';
    $config['cur_tag_close'] = '</b>';

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

now the pagination display like this :

1 2 3 >

and if i navigate to page 2 my URL will be http://blablabla.com/blablabla/2 and the data loaded correctly also the pagination will be

< 1 2 3 >

but if i go to the last page, the URL will be http://blablabla.com/blablabla/3 which is fine, the data loaded also correct but the pagination will be

1 2 3 >

when i go to last page, the first page link will be highlighted. Is there any problem with my config?

I think you need to change :
$config["uri_segment"] = $this->uri->segment(2);
to
$config["uri_segment"] = 2;
because you just need to mention uri-segment numer here, if you put like this $this->uri->segment(2) system will take value at segment 2 as $config["uri_segment"] and if that segment is not exist it will highlight first page as current page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM