2013-01-12 4 views
2

좋아, 나는 지난 1 시간 동안이 일을 해왔다. 페이지 수가 정확합니다. 지금 두 페이지가 있어야합니다. 나는 지금 그것을 5로 제한하고 있으며 7 개의 결과를 가지고있다. 그러나 2 페이지를 클릭하면 다른 두 게시물이 표시되지 않습니다. 지금 포럼 URL은 다음과 같습니다 : 포럼/카테고리/2 (포럼 컨트롤러, 카테고리 방법, 카테고리 ID는 2) 페이지는 다음과 같이 생각됩니다 : 포럼/카테고리/2/1 페이지 1 및 포럼/카테고리/2/2 페이지 2 등 그러나, 2 페이지 URL이 내게주는 :CodeIgniter 페이지 매김 - 이상한 행동을하는 페이지 링크

포럼/카테고리/5 ... 어떤 카테고리 ID 5가 없습니다. 하지만 카테고리 ID 2의 두 번째 페이지로 연결되어야합니다! 그래서 나는 확신 할 수 없다. 단지 페이지 당 5를 보여주고 있기 때문에 그것은 5를 보여줄 것인가? 확실하지가 작동하지만 여기 내 다음 코드 방법 :

//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와에서 처리 :

이보십시오. check http://stackoverflow.com/questions/18025993/pagination-current-link-not-highlighting/32863062#32863062 – vineet

답변

0

$config['uri_segment']는, 현재 페이지를하지를 결정하는 CI에 의해 사용됩니다

여기
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(); 
} 

는 해당 컨트롤러에 사용되는 내 기능입니다 링크를 생성합니다.

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

황금 (: 감사합니다! – Peanut

관련 문제