我有類似以下爲我的分頁功能,下面的一段代碼:在Codeigniter分頁中替換get參數?
public function news()
{
$this->load->library('pagination');
$config = array();
$config["base_url"] = base_url() . "index.php/welcome/news";
$this->load->model('news_model');
$total_row = $this->news_model->record_count();
$config["total_rows"] = $total_row;
$config["per_page"] = 1;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total_row;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['page_query_string'] = TRUE;
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';
$config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
$this->pagination->initialize($config);
if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}
else{
$page = 1;
} //echo $config["per_page"].'/'.$page; exit();
$this->load->model('news_model');
$data["results"] = $this->news_model->fetch_data($config["per_page"], $page);
$str_links = $this->pagination->create_links();
$data["links"] = explode(' ',$str_links);
$this->load->model('news_model');
$data['lt_news'] = $this->news_model->get_lt_newsletter();
$data['rm_news'] = $this->news_model->get_rm_newsletter();
$this->load->view('newsletter/newsletter',$data);
}
從上面的代碼中,URL瀏覽器顯示類似如下: -
http://localhost/ins/index.php/welcome/news?per_page=2
我很喜歡卡作爲如何將其更改爲如下所示:
http://localhost/ins/index.php/welcome/news/2
有沒有辦法做到這一點..?我是codeigniter中的分頁新手,所以我不知道是否有必要將url參數更改爲如上所示..?
是的,它的工作就像一個辦法,我需要的,但只是想知道的信息,什麼是目的使它成爲'真'? – Keynes
有些人可能更喜歡使用查詢字符串進行分頁。例如。 http://localhost/index.php/category/123/thread/123/2 <<可能在URL片段中的數字太多。 –
謝謝克里斯,我想了解分頁的邏輯。我還從我的一位朋友那裏看到了一篇文章。你能幫助我們嗎?https://stackoverflow.com/questions/44450973/codeigniter-pagination-logic-to-show-2-lists-per-page – Keynes