[eluser]skeletonfriend[/eluser]
How do I use the pagination class?
I have my controller, model, and view. In the view I have the correct amount of rows shown and pagination-links are there too, but when I try to click on of the page-links, I get an 404!
What can be the problem?
Code:
// controller
$config['base_url'] = base_url() . 'blog/';
$config['total_rows'] = $this->blog_model->getTotals();
$config['per_page'] = '20';
$this->pagination->initialize($config);
$num = $config['per_page'];
$offset = $this->uri->segment(3);
$data['blog_query'] = $this->blog_model->getBlogs($num, $offset);
// model
function getBlogs($num, $offset)
{
$this->db->select('a.id, a.name, DATE_FORMAT(a.date_created, "%Y-%m-%d") AS date_created, a.author, CASE WHEN COUNT(b.comment_id) < 1 THEN "" ELSE CONCAT(COUNT(b.comment_id), " comments") END AS comment_total');
$this->db->from('it_news a');
$this->db->join('it_news_comments b', 'a.id = b.news_id', 'left');
$this->db->groupby('a.id, a.name, a.author');
$this->db->orderby('a.date_created DESC');
$this->db->limit($num, $offset);
$query = $this->db->get();
if ($query->num_rows() > 0) { return $query->result(); }
}
// view
<?php foreach ($blog_query as $row): ?>
<div class="blogg-item">
<h2><?=anchor('blog/post/'. $row->id, $row->name);?></h2>
<p>Publicerad <?=$row->date_created;?> av <span><?=$row->author;?> <?=$row->comment_total;?></span></p>
</div>
<?php endforeach;?>
<div id="pager"><?=$this->pagination->create_links();?></div>