好吧,我一直在這個過去的一個小時,不能爲我的生活弄清楚這一點。 它的頁數正確..就像我現在應該有兩頁。我現在限制在5點,並有7個結果。但是,當我點擊第2頁時,它不會顯示其他兩個帖子。 現在,我的論壇網址是這樣的: 論壇/分類/ 2(論壇控制器,分類法,2類ID) 我想的網頁,然後去如下:對於網頁論壇/分類/ 2/1 1和論壇/分類/ 2/2 2等網頁和。然而,2頁給我這個作爲URL:CodeIgniter分頁 - 頁面鏈接代理怪異
論壇/分類/ 5 ......哪一類ID 5沒有話題了。但它應該導致類別ID 2的第二頁!所以我不確定...它可能會顯示5,因爲它只顯示每頁5個?不知道如何工作,但這裏是我下面的代碼:
public function category($id, $page = NULL) {
//grab topics
parent::before();
$data['forum_title'] = $this->forum->get_cat($id);
$data['id'] = $id;
$config = array();
$config['base_url'] = base_url() . 'forum/category/';
$config['total_rows'] = $this->forum->topic_count($id);
$config['per_page'] = 5;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$page = ($this->uri->segment($config['uri_segment'])) ? $this->uri->segment($config['uri_segment']) : 0;
$data['topics_array'] = $this->forum->get_topics($id, $config['per_page'], $page);
$data['links'] = $this->pagination->create_links();
$this->load->view('forum/category', $data);
parent::after();
}
這裏是我的函數,它們在控制器中使用:
//count the topics in a certain category id for pagination
public function topic_count($id) {
$this->db->where('cat_id', $id);
$this->db->from('forum_topic');
return $this->db->count_all_results();
}
//get all topics in a certain category
public function get_topics($id, $limit, $start) {
$this->db->distinct();
$this->db->select('t.id, t.title, t.sticky, t.locked, u.username as author, COUNT(p.id) as postcount, (SELECT u.username
FROM forum_post fp
INNER JOIN user u ON fp.author_id = u.user_id
WHERE fp.topic_id = t.id
ORDER BY fp.date DESC
LIMIT 1) as lposter, (SELECT fp.date
FROM forum_post fp
WHERE fp.topic_id = t.id
ORDER BY fp.date DESC
LIMIT 1) as lastdate');
$this->db->from('forum_topic t');
$this->db->join('user u', 'u.user_id = t.author_id', 'inner');
$this->db->join('forum_post p', 'p.topic_id = t.id', 'inner');
$this->db->where('t.cat_id', $id);
$this->db->group_by('t.id, t.title, t.sticky, t.locked, author, lposter, lastdate');
$this->db->order_by('t.sticky desc, p.date desc');
$this->db->limit($limit, $start);
return $this->db->get()->result();
}
我面臨同樣的問題,然後從jQuery的處理。檢查http://stackoverflow.com/questions/18025993/pagination-current-link-not-highlighting/32863062#32863062 – vineet