2013-01-12 18 views
2

好吧,我一直在这个过去的一个小时,不能为我的生活弄清楚这一点。 它的页数正确..就像我现在应该有两页。我现在限制在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(); 
} 
+0

我面临同样的问题,然后从jQuery的处理。检查http://stackoverflow.com/questions/18025993/pagination-current-link-not-highlighting/32863062#32863062 – vineet

回答

0

$config['uri_segment']用于通过CI来确定当前的页面,而不是生成链接。

试试这个:

$config['base_url'] = site_url('forum/category/' . $id); 
+0

黄金(:谢谢! – Peanut