在codeigniter(ver.3)上开发站点时,会发生错误:分页无法正常工作。只有在第四个URL段设置分页时才会发生这种情况。
我的控制器(在主课程中)
public function category($id=NULL){
$data['category'] = $this->articles_model->get_category($id);
$this->load->library('pagination');
$config['base_url'] = base_url().'main/category/'.$id.'/';
$config['total_rows'] = $this->articles_model
>count_all_articles();
$config['per_page'] = 10;
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$this->pagination->initialize($config);
$data['articles'] = $this->articles_model- >get_articles($config['per_page'],$page,$id);
$data['links'] = $this->pagination->create_links();
}
像工作一样的链接,但只突出显示第一页。在第二页和后一页上,第一页也会突出显示。
答案 0 :(得分:1)
答案 1 :(得分:0)
我遇到了同样的问题,但我解决了它,而且效果很好:
//u need to get the category id from the segment #3
$catid = $this->uri->segment(3);
//here is the segment of pagintation
$config["uri_segment"] = 4;
/*
here is the essantial work, where you should add the category id in the last of the base url
*/
$config["base_url"] = base_url() . "home/category/$catid";