I'm trying to use codeigniter pagination for my products so there are multiple pages which products but its not working for me and I don't know why..
This is my pagination function in my controller:
//code om in allecadeaus te bepalen hoeveel producten er per pagina zitten
public function pagination() {
//load pagination library
$this->load->library('pagination');
//laad Products_model voor pagination
$this->load->model('Pagination_model');
$this->load->model('Product_model');
$config = array();
$config["base_url"] = base_url() . "AlleCadeausController/pagination";
$config["total_rows"] = $this->products->record_count();
$config["per_page"] = 24;
$config['cur_tag_open'] = '<a><b class="text-success">';
$config['cur_tag_close'] = '</b></a>';
$config["uri_segment"] = 3;
$config['use_page_numbers'] =True;
$config['enable_query_strings'];
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data['title'] = "Products";
$data['products'] = $this->Product_model->selectProducts();
$data["links"] = $this->pagination->create_links();
$this->load->view("allecadeaus", $data);
}
with this line I'm getting all the products from product table:
$data['products'] = $this->Product_model->selectProducts();
My pagination model:
<?php
class Pagination_model extends CI_Model
{
public function __construct() {
parent::__construct();
}
public function record_count() {
return $this->db->count_all("products");
}
public function fetch_products($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->get_where('users',array('Is_Hidden'=>0));
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
?>
On my all products page I now tried to echo links but it doesn't work. I don't see the correct links and its just 1 link that leads to something else. This is the code in my view on the all products page:
<div class="text-center"><nav aria-label="Page navigation">
<ul class="pagination">
<li><?php echo $links; ?></li>
</ul>
</nav></div>
What am I doing wrong?