Welcome Guest, Not a member yet? Register   Sign In
404 error when using pagination
#1

[eluser]nitrammit[/eluser]
I'm trying to use the pagination class on my website, but when I click on page 2+, it returns a 404 error.

Here is some of my code:

1. Firstly, I'm using a route:

Code:
$route['threads/:num'] = 'threads/thread_lookup';

2. My controller:

Code:
public function thread_lookup()

{

if ( ! $this->ion_auth->logged_in())

{

  redirect('login', 'location');
  
}

$thread_id = $this->uri->segment(2);

$config['base_url'] = site_url("threads/$thread_id");
$config['total_rows'] = $this->db->get('post')->num_rows();
$config['per_page'] = 1;
$config['num_links'] = 20;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li>';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="current"><a>';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';

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

$data['thread'] = $this->forums_model->get_thread_info($thread_id);
$data['posts'] = $this->forums_model->get_posts($thread_id, $config['per_page'], $this->uri->segment(3));
  
$this->load->view('thread_view', $data);

}

3. My model:

Code:
function get_posts($thread_id, $per_page, $offset)

{

$this->db->select('post.id, post.user_id, post.date_posted, post.content, post.status_visible, user.username, user.location, user.psn, user.clan');
$this->db->from('post');
$this->db->join('user', 'user.id = post.user_id', 'left');
$this->db->where('thread_id', $thread_id);
$this->db->group_by('post.id');
$this->db->order_by('date_posted', 'asc');
$this->db->limit($per_page, $offset);
$query = $this->db->get();

if ($query->num_rows() > 0)

{

  return $query->result();

}

else

{

  redirect('forums', 'location');

}

}

4. And finally, my view contains:

Code:
echo $this->pagination->create_links();

I'm guessing this isn't working because of the route? How could I fix this problem?

Thanks!
#2

[eluser]nitrammit[/eluser]
All good, I fixed it. Needed to add another routing rule.

Code:
$route['threads/:num/:num'] = 'threads/thread_lookup';




Theme © iAndrew 2016 - Forum software by © MyBB