简体   繁体   English

如何更改 Codeigniter 分页查询字符串

[英]how to Change Codeigniter pagination query string

I want to change CodeIgniter pagination query string.我想更改 CodeIgniter 分页查询字符串。 When I use query string it will run & the url is good but data remaining same, without query string it will run properly.当我使用查询字符串时,它将运行并且 url 很好,但数据保持不变,如果没有查询字符串,它将正常运行。

My URL look like我的网址看起来像

example.com/1 

But I want it to be like但我希望它像

example.com?page=1

Here is my controller code..这是我的控制器代码..

$this->load->library('pagination');

$config['base_url'] = base_url().'/purchase/index';
$config['total_rows'] = $this->db->count_all('purchase');
$config['per_page'] = 10;
$config['page_query_string'] = TRUE;
$config['query_string_segment'] = 'page';

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

$page =($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

$data['pur_list'] = $this->purchase_model->purchase_list($config['per_page'],$page);

this will give you output like这会给你输出像

example.com?page=1&q=banana
$config = $this->config->item('pagination_config');
$config["base_url"] = base_url("search");
$config["total_rows"] = $this->SearchModel->getResultCount($query);
$config["per_page"] = 6;
$config['enable_query_strings'] = TRUE;
$config['page_query_string'] = TRUE;
$config['use_page_numbers'] = TRUE;
$config['reuse_query_string'] = TRUE;
$config['query_string_segment'] = 'page';
$this->pagination->initialize($config);
$current_page = $this->input->get('page',0);
$this->data["links"] = $this->pagination->create_links();
$this->data['results'] = $this->SearchModel->getResults($query, $config["per_page"], $current_page);
public function index()
  {
    $config = [];
    $config["base_url"] = base_url() . "admin/subscribers";
    $config["total_rows"] = $this->subscriber_model->count();
    $config["per_page"] = 10;
    $config['num_links'] = 9;
    $config['enable_query_strings'] = TRUE;
    $config['page_query_string'] = TRUE;
    $config['use_page_numbers'] = TRUE;
    $config['query_string_segment'] = 'page';
    $this->pagination->initialize( $config );
    $offset = ($this->input->get('page')) ? ( ( $this->input->get('page') - 1 ) * $config["per_page"] ) : 0;
    $data["results"] = $this->subscriber_model->get($config["per_page"], $offset );
    $data["links"] = explode(' ', $this->pagination->create_links() );
    $this->load->view("index", $data);
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM