[eluser]Skoobi[/eluser]
Hi im having slight issues trying to get the pagination to work. I think its because im using routes...
Ive tried a few thing but i cant seem to get it to work... It doesn't seem to choose 5 posts it displays all of them and then if you click the next page it throws a 404.
Heres the controller:
Code:
//-------------------------------------------------------------------------------
// PAGES
//--------------------------------------------------------------------------
public function index()
{
$this->load->library('pagination');
$data['pageTitle'] = 'My Title';
$data['posts'] = $this->posts_model->get_posts();
$postCount = $this->posts_model->get_post_count();
$this->load->library('pagination');
$config['base_url'] = 'http://www.my_url.com/blog/';
$config['total_rows'] = $postCount;
$config['per_page'] = 5;
$config['uri_segment'] = 2;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul><!--pagination-->';
$config['first_link'] = '« First';
$config['first_tag_open'] = '<li class="prev page">';
$config['first_tag_close'] = '</li>';
$config['last_link'] = 'Last »';
$config['last_tag_open'] = '<li class="next page">';
$config['last_tag_close'] = '</li>';
$config['next_link'] = 'Next →';
$config['next_tag_open'] = '<li class="next page">';
$config['next_tag_close'] = '</li>';
$config['prev_link'] = '← Previous';
$config['prev_tag_open'] = '<li class="prev page">';
$config['prev_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page">';
$config['num_tag_close'] = '</li>';
// $config['anchor_class'] = 'follow_link';
$this->pagination->initialize($config);
$data['pagination'] = $this->pagination->create_links();
$this->load->view('includes/header', $data);
$this->load->view('posts/index', $data);
$this->load->view('includes/footer');
}
Heres the model:
Code:
public function get_posts()
{
$this->db->order_by('dateAdded', 'desc');
$query = $this->db->get('posts');
return $query->result_array();
}
public function get_single_post($title)
{
$query = $this->db->get_where('posts', array('niceTitle' => $title));
return $query->row_array();
}
public function get_post_count()
{
$query = $this->db->select()->where('status', 1)->limit(5)->count_all_results('posts');
return $query;
}
and the routes:
Code:
$route['blog'] = "posts";
$route['blog/(:num)'] = "posts/$1";
$route['blog/(:any)'] = "posts/post/$1";
Any Ideas???
Cheers
Chris