2

好的,过去一个小时我一直在做这件事,我一生都无法弄清楚这一点。它的页数正确..就像我现在应该有两页。我现在将它限制在 5 并且有 7 个结果。但是,当我单击第 2 页时,它不会显示其他两个帖子。现在,我的论坛 URL 是这样的:forum/category/2(论坛控制器,类别方法,类别 ID 为 2)我认为页面如下所示:forum/category/2/1 用于第 1 页和论坛/category/2/2 用于第 2 页等.. 但是,第 2 页给了我这个 URL:

forum/category/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();
}
4

1 回答 1

0

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

试试这个:

$config['base_url'] = site_url('forum/category/' . $id);
于 2013-01-12T20:37:37.907 回答