当我在CodeIgniter中单击带有以下代码的下一个分页按钮时,得到的数据相同
public function view($slug){
$data['title']= $slug;
$data['description']= "None";
$postdatacount = $this->Constant_model->snippettagscount($slug);
$checktags= $this->Constant_model->gettags($slug);
if($checktags>0){
if ($postdatacount>0) {
$config = array();
$config["base_url"] = base_url() ."tags/".$slug;
$config["total_rows"] = $postdatacount;
$config["per_page"] = 6;
$config["uri_segment"] = 2;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['first_link'] = false;
$config['last_link'] = false;
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_link'] = '«';
$config['prev_tag_open'] = '<li class="prev">';
$config['prev_tag_close'] = '</li>';
$config['next_link'] = '»';
$config['next_tag_open'] = '<li>';
$config['next_tag_close'] = '</li>';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="active"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$this->pagination->initialize($config);
$page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
$data["links"] = $this->pagination->create_links();
$data["title"] = "All Tags";
$data["description"] = "All Tags";
$data['snippets_tags'] = $this->Constant_model->get_tags($config["per_page"],$page,$slug);
$this->snippetfunctions->add_count('tags','tag_name',$slug);
$this->load->view('view_tag_snippets', $data);
}else {
$data["title"] = "No Snippet Found for this Tag";
$data["description"] = "No Snippet Found for this Tag";
$data["slug"] =$slug;
$this->load->view('error_tags',$data);
}
}else{
$this->load->view('404',$data);
}
}
此功能上的主要URL是
当我单击“下一步”按钮时,将创建以下URL,但不会加载下一个数据,而是加载相同的数据,并且在每个下一页上都会发生相同的事情。
我正在使用的路由是
$route['tags/(:any)/(:num)'] = 'tags/view/$1/$2';
$route['tags/(:any)'] = 'tags/view/$1';
答案 0 :(得分:2)
问题出在配置$config["uri_segment"] = 2;
上,根据您的路由,页面变量位于第3段。
使用$config["uri_segment"] = 3;
代替$config["uri_segment"] = 2;
。同时更改行$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
更多详细信息read