[eluser]zyzzzz[/eluser]
This is the code for my entire controller function:
Code:
// Get and set page number
$page_settings = $this->uri->ruri_to_assoc(2);
$current_page = ((isset($page_settings['page']) && is_numeric($page_settings['page'])) ? $page_settings['page'] : 1);
// What is the limit and offset?
$limit = self::TAGS_PER_PAGE;
$offset = ($current_page - 1) * self::TAGS_PER_PAGE;
// Get the TAGS_PER_PAGE most popular tags with thier count
$sql = "SELECT tags.name, COUNT(*) AS count
FROM tags
INNER JOIN codes_tags ON tags.id = codes_tags.tag_id
GROUP BY tags.id
UNION
SELECT tags.name, '0'
FROM tags
WHERE tags.name not in
(SELECT tags.name
FROM tags
INNER JOIN codes_tags ON tags.id = codes_tags.tag_id)
ORDER BY count(*) DESC
LIMIT $offset, $limit";
$tags = $this->db->query($sql)->result_array();
// How many tags are there in total?
$sql = 'SELECT COUNT(*) as count
FROM tags';
$row = $this->db->query($sql)->row_array();
$total_tags = $row['count'];
// Create links
$this->load->library('pagination');
$config = array
(
'base_url' => site_url('tag_index/page'),
'total_rows' => $total_tags,
'per_page' => self::TAGS_PER_PAGE,
'uri_segment' => 3
);
$this->pagination->initialize($config);
// Render partial page
$partial_data = array
(
'tags' => $tags,
'pagination' => $this->pagination->create_links()
);
$partial_rendered = $this->load->view('pages/partial/tag-index', $partial_data, TRUE);
// Generate the sidebar
$this->load->library('sidebar');
$sidebar = $this->sidebar->add('login')
->add('popular-tags')
->generate();
// Generate the full page view
$layout_data = array
(
'title' => "Tag Index - Page $current_page",
'content' => $partial_rendered,
'sidebar' => $sidebar
);
$this->load->view('pages/layout', $layout_data);
This is what is being passed to the pagination library with initialize function (the config array):
Code:
Array
(
[base_url] => http://localhost/tag_index/page
[total_rows] => 188
[per_page] => 30
[uri_segment] => 3
)
The problem is, the create_links() function is giving me links like this:
Page 1 => 'tag_index/page/'
Page 2 => 'tag_index/page/30'
Page 3 => 'tag_index/page/60'
When what I really want is this:
Page 1 => 'tag_index/page/1'
Page 2 => 'tag_index/page/2'
Page 3 => 'tag_index/page/3'
What am i doing wrong here?