我使用codeigniter创建了一个分页
首先我使用类别ID($ id)来显示该类别下的相关文章,并且因为菜单可以具有子类别,所以我在数组中创建id列表以从该数组中选择post:这是来自的链接菜单:
<li><a href="<?php echo base_url(); ?>article/category/
<?php echo $category->cat_id;?>">
<span class="ion-ios7-arrow-right nav-sub-icn"></span>
<?php echo $category->cat_name;?></a></li>
因此,点击上面的链接,它会在分页的第一页正确显示该类别的文章,但是当我点击分页的下一个链接时它会起作用但是它会更改类别的ID,因此不会查询文章:文章控制器中方法类别的代码如下:
public function category($x =''){
$total_rows = $this->article_model->count();
$config['total_rows'] =$total_rows;
$config['per_page'] =$this->limit;
$config['uri_segment']=4;
$config['base_url'] = base_url().'article/category';
$this->pagination->initialize($config);
if (!empty($x)) {
$data['categories'] = $this->category_model->listAll();
$cond['condition']=array('cat_id'=>preg_replace('#[^0-9]#', '', $x));
$data['index'] = $this->category_model->view($cond);
$data['view'] = $this->article_model->all_article_by_category($x ,$this->limit);
$data['page_link'] = $this->pagination->create_links();
$this->load->view('article/category', $data);
}else{
redirect('/home', 'refresh');
}
}
这是文章模型中的代码:
function all_article_by_category($cat_id, $limit){
$offset =$this->uri->segment(4);
$this->db->select(array('art_id','title','description','public_date','image','username','created','cat_id'));
$this->db->from($this->tbl_article);
$this->db->join($this->tbl_user, 'tbl_user.user_id = tbl_article.u_id');
$this->db->where('cat_id', $cat_id);
$this->db->order_by('created','desc');
return $this->db->limit($limit, $offset)->get();
}
答案 0 :(得分:1)
尝试将类别ID添加到分页基本网址:
$config['base_url'] = base_url().'article/category/' . $x;