如何从Codeigniter中的URL中删除“&per_page =”
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何从Codeigniter中的URL中删除“&per_page =”相关的知识,希望对你有一定的参考价值。
我坚持这个问题。我在我的网址上遇到了这个问题。我在我的网址中收到&per_page=
。
我在CI中使用分页,其中我使用了以下代码但无法将其删除。
我的网址:http://localhost/abroad_education/entrance/index/0&per_page=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;
来自docs。
如果将$ config ['enable_query_strings']设置为TRUE,将使用查询字符串自动重写链接。也可以显式设置此选项。
以上是关于如何从Codeigniter中的URL中删除“&per_page =”的主要内容,如果未能解决你的问题,请参考以下文章
如何从 Codeigniter 中的 URL 中删除“&per_page=”
如何从Codeigniter中的URL中删除“&per_page =”
无法从 codeigniter 中的 URL 中删除“Index.php”
Codeigniter 3.1.6 - 如何从 url 中删除 index.php