当我在URL中传递参数时,我在codeigniter上设置分页时遇到问题
如果我的网址是这样的: search/?type=groups
什么应该是我$config['base_url']的分页工作?
如果我将基本网址设置search/?type=groups为生成的网址是search/?type=groups/10
意思是 $_GET['type']=groups/10
谢谢
Aur*_*rel 98
在分页配置中:
if (count($_GET) > 0) $config['suffix'] = '?' . http_build_query($_GET, '', "&");
Run Code Online (Sandbox Code Playgroud)
您当前的$_GET变量将显示在分页链接中.您可以用$_GET另一个关联数组替换.除非已存在查询字符串,否则不会添加查询字符串.
更新: 我刚刚看到,如果你从另一个分页号码返回点击第一个(1),CI不再关心你的后缀配置.
解决这个问题$config['first_url'].
例如: $config['first_url'] = $config['base_url'].'?'.http_build_query($_GET);
mer*_*ran 20
这个问题的最新答案是;
您应该通过启用此配置来启用查询字符串的重用:
$config['reuse_query_string'] = true;
Run Code Online (Sandbox Code Playgroud)
之后你应该初始化分页:
$this->pagination->initialize($config);
Run Code Online (Sandbox Code Playgroud)
添加
$config['reuse_query_string']以允许自动重新填充查询字符串参数,并结合常规URI段.- CodeIgniter 3.0.0更改日志
这是我的 jquery 解决方案:
只需将分页链接包装在一个 div 中,如下所示:
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
Run Code Online (Sandbox Code Playgroud)
比添加以下 jquery 代码:
$("#pagination > a").each(function() {
var g = window.location.href.slice(window.location.href.indexOf('?'));
var href = $(this).attr('href');
$(this).attr('href', href+g);
});
Run Code Online (Sandbox Code Playgroud)
对我来说很好用。
解决方案是 CodeIgniter 的功能不是这样的。我需要的是“类型”中每个选项的方法(在控制器中),因此一个选项是一种名为 :groups 的方法,另一个称为条目等,每个方法根据需要引用不同的模型类或方法。
我正在尝试更好地理解 OOP 和 CI ...需要进行一些调整...如果我错了,请随时发表评论并纠正我。谢谢
| 归档时间: |
|
| 查看次数: |
43418 次 |
| 最近记录: |