I have Codeigniter setup for pagination, which is working properly except that it does not show the First and Last options. It does show previous and next.
I have setup this config as follows:
$config = array();
$config["base_url"] = base_url() . "index.php/main";
$config["total_rows"] = $this->Pages_model->user_count();
$config["per_page"] = 15;
$config["uri_segment"] = 2;
$num_pages = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($num_pages);
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['first_link'] = '<<';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['last_link'] = '>>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['next_link'] = '>';
$config['next_tag_open'] = '<li>';
$config['prev_link'] = '<';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$seg = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data['loaded'] = $this->Content_model->loadVisitors($config["per_page"], $seg);
$data["links"] = $this->pagination->create_links();
$this->load->view('pages/'.$page, $data);
What am I missing to have a First and Last feature? I can't seem to find anything in the docs.
EDIT: also just to mention, my view is as follows:
<div class="container text-center">
<div class="row">
<div class="col-lg-12">
<?php echo $links; ?>
</div>
</div>
</div>
When I inspect the page, this is what it shows:
<div class="col-lg-12">
<ul class="pagination">
<li><a href="index.php/main" data-ci-pagination-page="1" rel="prev"><</a></li>
<li><a href="index.php/main" data-ci-pagination-page="1" rel="start">1</a></li>
<li class="active"><a href="#">2</a></li>
<li><a href="index.php/main/30" data-ci-pagination-page="3">3</a></li>
<li><a href="index.php/main/45" data-ci-pagination-page="4">4</a></li>
<li><a href="index.php/main/60" data-ci-pagination-page="5">5</a></li>
<li><a href="index.php/main/30" data-ci-pagination-page="3" rel="next">></a></li>
</ul>
</div>
Try this:
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
To show text in first and last link you should place string in quotes.
$config['first_link'] = 'First';
$config['last_link'] = 'Last';
You can get proper documentation here https://ellislab.com/codeigniter/user-guide/libraries/pagination.html
It turns out this code was causing it not to show First and Last
$num_pages = $config["total_rows"] / $config["per_page"];
$config["num_links"] = round($num_pages);
Removing this code it works. Fortunately, I did not necessarily need this, however if anyone knows why this stopped it from working, I would appreciate a response to that.
you have to include last and first tags and their opening and closing tags like this...
for first tag.....
$config['first_link'] = 'First';
$config['first_tag_open'] = '<li>'
$config['first_tag_close'] = '</li>';
for last tag.....`
$config['last_link'] = 'Last';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';`
I have the same issue right now; I think if you have only a few pages & there are already numbered links to those pages, the first or last will disappear.
Problem must be in core file, change the following things min your core file and try it. system/libraries/pagination.php
line 231 – first link
$output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.'">'.$this->first_link.'</a>'.$this->first_tag_close;
TO
$output .= $this->first_tag_open.'<a '.$this->anchor_class.'href="'.$first_url.$this->suffix.'">'.$this->first_link.'</a>'.$this->first_tag_close;
line 285 – 1 link
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.'">'.$loop.'</a>'.$this->num_tag_close;
TO
$output .= $this->num_tag_open.'<a '.$this->anchor_class.'href="'.$this->first_url.$this->suffix.'">'.$loop.'</a>'.$this->num_tag_close;
add $this->suffix variable after $this->first_url value i think you must not ‘hack’ the $this->first_url value to concat with $this->suffix, it will ruined the ‘if’ decision in line above i hope this will work for you.