簡體   English   中英

如何從Codeigniter中的URL中刪除“&per_page =”

[英]How to remove “&per_page=” from URL in Codeigniter

我堅持這個問題。 我在我的網址上遇到了這個問題。 我在我的網址中獲得&per_page=

我在CI中使用分頁,其中我使用了以下代碼但無法將其刪除。

我的網址: http:// localhost / abroad_education / entrance / index / 0&per_page = 3

預期網址: http:// localhost / abroad_education / entrance / index / 0/3

調節器

class Entrance extends CI_Controller
{
public function __construct()
{ 
    parent::__construct();  
    $this->load->helper('url');
    $this->load->helper('form');

    $this->load->model('Pagination_model',"pgn");
}

public function index()
{   


    if($this->input->post('title') !="")
    {
        $title = trim($this->input->post('title'));
    }
    else{
        $title = str_replace("%20",' ',($this->uri->segment(3))?$this->uri->segment(3):0);
    } 

    $data['search_title']=$title;       
    print_r($title); 
    $allrecord = $this->pgn->allrecord($title);
    $baseurl =  base_url().$this->router->class.'/'.$this->router->method."/".$title;

    $paging=array();
    $paging['base_url'] =$baseurl;
    $paging['total_rows'] = $allrecord;
    $paging['per_page'] = 3;
    $paging['uri_segment']= 4;
    $paging['num_links'] = 8;
    $paging['first_link'] = 'First';
    $paging['first_tag_open'] = '<li>>';
    $paging['first_tag_close'] = '</li>';
    $paging['num_tag_open'] = '<li>';
    $paging['num_tag_close'] = '</li>';
    $paging['prev_link'] = 'Prev';
    $paging['prev_tag_open'] = '<li>';
    $paging['prev_tag_close'] = '</li>';
    $paging['next_link'] = 'Next';
    $paging['next_tag_open'] = '<li>';
    $paging['next_tag_close'] = '</li>';
    $paging['last_link'] = 'Last';
    $paging['last_tag_open'] = '<li>';
    $paging['last_tag_close'] = '</li>';
    $paging['cur_tag_open'] = '<li class="active"><a href="javascript:void(0);">';
    $paging['cur_tag_close'] = '</a></li>';

    $this->pagination->initialize($paging); 

    $data['limit'] = $paging['per_page'];
    $data['number_page'] = $paging['per_page']; 
    $data['offset'] = ($this->uri->segment(4)) ? $this->uri->segment(4):'0/';   
    $data['nav'] = $this->pagination->create_links();
    $data['datas'] = $this->pgn->data_list($data['limit'],$data['offset'],$title);
    $data['include'] = 'frontend/entrance/entrance';
    $this->load->view('frontend/container', $data);
}

}

模型

class Pagination_model extends CI_Model{
function __construct(){
parent::__construct();  
    $this->load->library(array('session','pagination'));
    $this->load->helper('url');
    $this->load->database();    
}


public function allrecord($title){
    if(!empty($title)){
        $this->db->like('ee_name',$title);
    }
    $this->db->select('*');
    $this->db->from('vm_entrance_exams');
    $rs = $this->db->get();
    return $rs->num_rows();
}

public function data_list($limit,$offset,$title){
    if(!empty($title)){
        $this->db->like('ee_name',$title);
    }
    $this->db->select('*');
    $this->db->from('vm_entrance_exams');
    $this->db->order_by('ee_id','ee_desc');
    $this->db->limit($limit,$offset);
    $rs = $this->db->get();
    return $rs->result_array();
}
}

檢查/application/config.php中的'enable_query_strings'是否設置為false

 $config['enable_query_strings'] = FALSE;

來自文檔

如果將$ config ['enable_query_strings']設置為TRUE,將使用查詢字符串自動重寫鏈接。 也可以顯式設置此選項。

暫無
暫無

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

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