dtvjl64442 2016-11-26 09:31
浏览 47
已采纳

使用查询字符串时,不会返回URI段

I'm trying to paginate the search results returned by the query. I have the following URL:

blog/search?query=post/5

Where I am trying to get the value of $start=5 from the URL using:

$start = $this->uri->segment(3);

It is not returning anything.

Where removing ?query=post, i.e, blog/search/5 works fine. But I want to keep the query parameter and read the value.

  • 写回答

1条回答 默认 最新

  • dpmwy80068 2016-11-26 09:46
    关注

    That's because of the ? character in the URI. CodeIgniter URI parser (and any other standard URI parser) does not recognize what you have in mind. After the ? character, it's all query string, not URI segments. See the output of PHP's parse_url():

    parse_url('blog/search?query=post/5')
    [
        "path" => "blog/search",
        "query" => "query=post/5",
    ]
    

    See? The first segment is blog, the second is search and the rest is the querystring.

    You need to change your URI design in an standard way. For example:

    blog/search/5?query=post
    

    So that the call to $this->uri->segment(3) will return what you have in mind.

    Speaking of CodeIgniter pagination library, see reuse_query_string and page_query_string configs in the documentation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等
  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行