簡體   English   中英

替換Codeigniter分頁中的get參數?

[英]Replace get parameters in Codeigniter pagination?

我的分頁功能的以下代碼如下:-

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'] = '&nbsp;<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('&nbsp;',$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參數更改為上面的樣子。

$config['page_query_string']為false。

從文檔https://www.codeigniter.com/userguide3/libraries/pagination.html#customizing-the-pagination中

默認情況下,分頁庫假定您使用的是URI段,並構造類似以下內容的鏈接:

http://example.com/index.php/test/page/20如果將$ config ['enable_query_strings']設置為TRUE,則將使用查詢字符串自動重寫鏈接。 也可以顯式設置此選項。 使用$ config ['page_query_string']設置為TRUE,分頁鏈接將變為:

http://example.com/index.php?c=test&m=page&per_page=20

使頁面成為函數的參數,如下所示:

public function news($pageNum)
    {
        ...
        $page = $pageNum
        ...
    }

然后,您應該可以通過以下方式訪問它:

http://localhost/ins/index.php/welcome/news/2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM