I am having problems with CodeIgniter pagination module.
When I go to click on the links I get a 404 error. As I understand and I may be incorrect, but it would seem that the URI segment which determines the offset is not being read inside the index function of my controller and that code igniter is actually looking for this as a function inside the controller hence throwing the 404 when it cant find it.
I have googled around and checked on the forum to find a solution but have not had any success. If anyone has any hints or tips that would be great I have included the relevant code from my controller, model and view below.
//Controller
$this->load->library('pagination');
$config['base_url'] = '/yourhistory/';
$config['total_rows'] = $this->db->get('gallery')->num_rows();
$config['per_page'] = 3;
$config['uri_segment'] = 2;
$this->pagination->initialize($config);
$data['galleryitems'] = $this->pages_model->get_gallery($config['per_page'], $config['uri_segment']);
$this->load->view('/gallery', $data);
//Model
function get_gallery($limit, $segment)
{
$query = $this->db->get('gallery', $limit, $this->uri->segment($segment));
if ($query->num_rows > 0)
{
foreach($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
//View
echo $this->pagination->create_links();
Well its going to fail first off because of your base_url:
You need the full path, altho I am just guessing here as you don’t provide the URL that is throwing the 404.
Notes on pagination here: http://codeigniter.com/user_guide/libraries/pagination.html