CI分页不起作用

时间:2015-03-11 16:33:48

标签: codeigniter pagination

我想在CI中使用分页但是当我点击链接时,我得到为每个分配的错误无效参数。我通过get方法从link获得了一个类别id。 第一个链接正在工作但是当我再次单击它时,它不起作用。这是我的链接:

<a href="<?php echo site_url('forum/topic')?>?t_id=<?php echo $topic->t_id; ?>&cat_id=<?php echo $category->cat_id ?>"><h4 class="media-heading"><?php echo $topic->topic_title ?></h4></a>

我不知道为什么它不起作用。请指导我 这是我的控制器

public function categories()
{
     $cat_id = $this->input->get('cate',TRUE);
     $data['cat_id'] = $cat_id;
     $data['categories_list'] = $this->mod_forum->categories_list();
     $count = $this->mod_forum->record_count_sort($data);

     $data['categories_pic'] = $this->mod_forum->categories_pic($data);


    $config = array();
    $config["base_url"] = base_url() . "index.php/forum/categories?cat=$cat_id";
    $config["total_rows"] = $count->num_rows();
    $config["per_page"] = 5;
    $config["uri_segment"] = 3;
    $config["cat_id"] = $cat_id;

    $this->pagination->initialize($config);

    $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
    $data["topics_sort"] = $this->mod_forum->fetch_sort_category($config["per_page"], $page,$config["cat_id"]);

    $data["sort"] = $this->pagination->create_links();
    $this->load->view('header');
    $this->load->view('navi');
    $this->load->view('forum/category_content',$data);
    $this->load->view('footer');

}

这是我的模特

public function record_count_sort($data) {
    return $this->db->get_where('topics',array('cat_id'=>$data['cat_id']));
    }

    public function fetch_sort_category($limit, $start,$cat_id) {
        $this->db->limit($limit, $start);
        $query = $this->db->get_where('topics',array('cat_id'=>$cat_id));
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }

这是我的观点

    <div class="col-md-6">
        <?php
        foreach ($topics_sort as $topic ) {?>
            <div class="media">
              <div class="media-left media-middle">
                <a href="">
                  <img class="media-object pull-left" src="" alt="">
                </a>
              </div>
              <div class="media-body">
                <a href=""><h4></h4></a>
                <a class="orange" href=""></a>
              </div>
            </div>          


        <?php }
         ?>
 <div><?php echo $sort; ?></div>
    </div>

0 个答案:

没有答案