简体   繁体   English

CI分页参数不断追加到base_url

[英]CI pagination parameter keeps appending to base_url

I am implementing a list of rows with pagination using CodeIgniter. 我正在使用CodeIgniter实现带有分页的行列表。 The problem is it keeps appending &page=n everytime I click on next page. 问题是,每次我单击下一页时,它都会不断添加&page=n

for example, initially if my URL is like 例如,最初,如果我的网址是

http://example.com/search/?a=1&b=2&page=1

and when I click on page two, it becomes 当我单击第二页时,它变成

http://example.com/search/?a=1&b=2&page=1&page=2

I tried playing with configs but doesn't seem to be working properly. 我尝试使用配置,但似乎无法正常工作。 Is that something to do with base_url ? 这与base_url吗? should I dynamically create base_url string without last parameter &page=n ? 我应该动态创建没有最后一个参数&page=n base_url字符串吗? I thought it would automatically re-write it. 我以为它将自动重写它。

pagination configs are as follows. 分页配置如下。

$page_config['base_url'] = $this->config->item('app_root') . $_SERVER['REQUEST_URI'];
$page_config['total_rows'] = $result['total'];
$page_config['per_page'] = 10;
$page_config['page_query_string'] = TRUE;
$page_config['query_string_segment'] = 'page';
$page_config['use_page_numbers'] = TRUE;

Thoughts? 有什么想法吗?

Please Add base_url this type 请添加base_url此类型

http://example.com/search/?a=1&b=2
$page_config['base_url'] = http://example.com/search/?a=1&b=2;

This is incorrect 这是不对的

$page_config['base_url'] = $this->config->item('app_root') . $_SERVER['REQUEST_URI'];

Codeigniter pagination add &page=n with the config['base_url'] Codeigniter分页将config['base_url']添加&page=n
But your base_url change each time at different page 但是您的base_url每次都在不同页面上更改

$page_config['base_url']='http://example.com/search/?a=1&b=2';//for first time and codeigniter added $page=1
$page_config['base_url']='http://example.com/search/?a=1&b=2&page=1';//for 2nd time and codeigniter added $page=2
$page_config['base_url']='http://example.com/search/?a=1&b=2&page=1&page=2';//for 3rd time and codeigniter added $page=3

Your base url should be fixed and not be dynamic. 您的基本网址应该是固定的,而不是动态的。 It should be 它应该是

$page_config['base_url']='http://example.com/search/?a=1&b=2';

you can do it like this but its bad 你可以这样做,但是不好

$page_config['base_url'] = $this->config->item('app_root') . str_replace("&page=".$_GET['page'],"",$_SERVER['REQUEST_URI']);

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

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