我遇到了分页链接的问题。
我路过他们,我最终做了:
$route['blog/(:num)'] = "page/blog/$1";
在查看,我做了
<?php foreach ($links as $link) { echo $link; } ?>
并在我的页面 控制器
public function blog(){
//GET SITE TITLE
$query = $this->db->get_where('settings', array('id' => 1));
foreach($query->result() as $rows) {
$data['site_title'] = 'Blog · ' . $rows->value;
}
//PAGINATE ITEMS
$config['use_page_numbers'] = TRUE;
$config['num_links'] = 5;
$config['base_url'] = base_url('blog/');
$config["total_rows"] = $this->pagination_model->count_posts();
$config['per_page'] = 2;
$config['full_tag_open'] = '<nav><ul class="pagination">';
$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>';
$config['full_tag_close'] = '</ul></nav>';
$config['next_tag_open'] = '<li><span aria-hidden="true">';
$config['next_link'] = '»';
$config['next_tag_close'] = '</span></li>';
$config['last_link'] = 'Last';
$config['last_tag_open'] = '<li>';
$config['last_tag_close'] = '</li>';
$config['first_link'] = 'First';
$config['first_tag_open'] = '<li>';
$config['first_tag_close'] = '</li>';
$config['prev_tag_open'] = '<li><span aria-hidden="true">';
$config['prev_link'] = '«';
$config['prev_tag_close'] = '</span></li>';
$this->pagination->initialize($config);
if($this->uri->segment(2)){
$page = ($this->uri->segment(2)) ;
}
else{
$page = 1;
}
$data["results"] = $this->pagination_model->fetch_posts($config["per_page"], $page);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ',$str_links );
$this->load->view('blog', $data);
}
到目前为止,分页工作正在进行,但链接并非如此。其活动状态保留在第1页,下一个和上一个链接不起作用。 我无法找出罪魁祸首。
修改
所以我设法编辑以下内容:
$config['base_url'] = base_url('page/blog');
if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}
else{
$page = 1;
}
现在它正在运作。但是,我需要将网址设为mysite.com/blog/$the_pagination_id