好的,过去一小时我一直在这里,并且不能因为我的生活而想到这一点。 它使页面数量正确..就像我现在应该有两页一样。我现在限制在5,有7个结果。但是,当我点击第2页时,它不会显示其他两个帖子。 现在,我的论坛网址是这样的: 论坛/类别/ 2(论坛控制器,类别方法,2类别ID) 我认为这些页面如下:论坛/类别/ 2/1页面1和论坛/类别/ 2/2页面2等等。但是,第2页给我这个URL作为:
论坛/类别/ 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 :(得分:0)
$config['uri_segment']
来确定当前页面,而不是生成链接。
试试这个:
$config['base_url'] = site_url('forum/category/' . $id);