任何人都知道如何解决我的问题.. 我的问题是基于类别工作的分页但是当我点击按钮分页时结果是找不到页面可能我的路线有问题但是我不确定那个...请帮帮我.. 这是我的路线
public function page($offset=0)
{
$id=$this->uri->segment('3');
$this->db->select('id,categoryId');
$this->db->from('t_blog_post');
$this->db->where('categoryId',$id);
$query= $this->db->get();
//$jml = $this->db->get('t_blog_post');
$config['base_url'] = base_url().'blog/category/'.$id.'/page';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = 2; /*Jumlah data yang dipanggil perhalaman*/
$config['uri_segment'] = 4; /*data selanjutnya di parse diurisegmen 3*/
/*Class bootstrap pagination yang digunakan*/
$config['full_tag_open'] = "<ul class='pagination pagination-sm' style='position:relative; top:-25px;'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
$list_blogPost=$this->BlogCategory->get_post($config['per_page'], $offset,$id);
$list_lastblogPost=$this->BlogCategory->get_last_post();
$list_blogCategory=$this->BlogCategory->get_category();
$data=array(
'title' => 'Blog',
'userId' => $this->session->userdata('sh_userId'),
'fullName' => $this->session->userdata('sh_fullName'),
'accountTypeId' => $this->session->userdata('sh_accountTypeId'),
'photo' => $this->session->userdata('sh_photo'),
'halaman' => $this->pagination->create_links(),
'offset' => $offset,
'listblogPost' => $list_blogPost,
'listlastblogPost'=> $list_lastblogPost,
'listblogCategory'=>$list_blogCategory
);
$this->template->display_admin('blog_categorypost',$data);
}
这是我的控制器
{{1}}
答案 0 :(得分:0)
由于您的网址有两个参数,因此您需要为该方法设置两条路线。将您的路线更改为
$route['blog/category/(:any)/page'] = 'Blog_Category_Post/page/$1/page';
$route['blog/category/(:any)/page/(:any)'] = 'Blog_Category_Post/page/$1/page/$2';
现在更改配置行base_url
,如下所示
$config['base_url'] = site_url('blog/category').'/'.$id.'/page';
最后你的page
控制器应该是
public function page($categoryId){
$this->db->select('id,categoryId');
$this->db->from('t_blog_post');
$this->db->where('categoryId',$categoryId);
$query= $this->db->get();
//$jml = $this->db->get('t_blog_post');
$config['base_url'] = site_url('blog/category/').'/'.$categoryId.'/page';
$config['total_rows'] = $query->num_rows();
$config['per_page'] = 2; /*Jumlah data yang dipanggil perhalaman*/
$config['uri_segment'] = 5; /*data selanjutnya di parse diurisegmen 3*/
/*Class bootstrap pagination yang digunakan*/
$config['full_tag_open'] = "<ul class='pagination pagination-sm' style='position:relative; top:-25px;'>";
$config['full_tag_close'] ="</ul>";
$config['num_tag_open'] = '<li>';
$config['num_tag_close'] = '</li>';
$config['cur_tag_open'] = "<li class='disabled'><li class='active'><a href='#'>";
$config['cur_tag_close'] = "<span class='sr-only'></span></a></li>";
$config['next_tag_open'] = "<li>";
$config['next_tagl_close'] = "</li>";
$config['prev_tag_open'] = "<li>";
$config['prev_tagl_close'] = "</li>";
$config['first_tag_open'] = "<li>";
$config['first_tagl_close'] = "</li>";
$config['last_tag_open'] = "<li>";
$config['last_tagl_close'] = "</li>";
$this->pagination->initialize($config);
if ($this->uri->segment(5)) {
$offset = $this->uri->segment(5);
} else {
$offset = 0;
}
$list_blogPost=$this->BlogCategory->get_post($config['per_page'], $offset,$categoryId);
$list_lastblogPost=$this->BlogCategory->get_last_post();
$list_blogCategory=$this->BlogCategory->get_category();
$data=array(
'title' => 'Blog',
'userId' => $this->session->userdata('sh_userId'),
'fullName' => $this->session->userdata('sh_fullName'),
'accountTypeId' => $this->session->userdata('sh_accountTypeId'),
'photo' => $this->session->userdata('sh_photo'),
'halaman' => $this->pagination->create_links(),
'offset' => $offset,
'listblogPost' => $list_blogPost,
'listlastblogPost'=> $list_lastblogPost,
'listblogCategory'=>$list_blogCategory
);
$this->template->display_admin('blog_categorypost',$data);
}
现在测试。