我被这个问题困住了。我的网址上有这个问题。我的url中有&per_page=
。
我在ci中使用分页,我在其中使用了以下代码,但无法删除它。
我的网址:http://localhost/abroad_education/entrance/index/0&per_page=3
需要的URL: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;
从docs开始。
如果$config['enable_query_strings']设置为true,则链接
将使用查询字符串自动重新写入。这个选项可以
也要显式设置。
关于php - 如何从Codeigniter中的网址中删除“&per_page =”,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47845409/