Muhammad Talha Muhammad Talha - 9 months ago 96
PHP Question

Last page active by Default Codeigniter pagination

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 pagination library.

What i am try to doing?
I have use codeigniter library and its work perfectly but i want to do active last page by default when i use this code it will always active first page by default.

public function example1() {
$config = array();
$config["base_url"] = base_url() . "welcome/example1";
$config["total_rows"] = $this->Countries->record_count();
$config["per_page"] = 20;
$config["uri_segment"] = 3;


$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->Countries->
fetch_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();

$this->load->view("example1", $data);

Now my link look like

1 2 3 4 5

1 page is active by default but i want to active what ever last page in this case it's 5 which could be active

1 2 3 4 5

Answer Source

You can define current page on Codeigniter with;

$config["cur_page"] = $your_last_page_number;

and manage pages in controller.