【问题标题】:Codeigniter uri_string not returning the full pathCodeigniter uri_string 未返回完整路径
【发布时间】:2012-02-24 22:57:51
【问题描述】:

因此位于此网址(例如):http://localhost/codeigniter-app/en/results?search_query=data

uri_string 没有返回所需的路径

["uri_string"]=>
  string(10) "en/results"

和预期的:

["uri_string"]=>
  string(10) "en/results?search_query=data"

我的一些config.php

$config['uri_protocol'] = 'AUTO';
$config['url_suffix'] = '';
$config['allow_get_array']      = TRUE;
$config['enable_query_strings'] = false;

有什么想法吗?

编辑:

使用http://codeigniter.com/wiki/CodeIgniter_2.1_internationalization_i18n库时发现问题

【问题讨论】:

  • 您能说一下您期望的结果吗?
  • 抱歉,我认为这很明显...检查编辑
  • 尝试将 [L,QSA] 添加到 htaccess 中包含 index.php 的行
  • @BenSwinburne 到底是哪一行? gist.github.com/d11be61ebca9bc49daab这个我试过RewriteRule ^(.*)$ index.php?/$1但是没有效果
  • 您的一个重写规则后面会有一个 [L]。添加 QSA

标签: php codeigniter uri pathinfo


【解决方案1】:

您已关闭查询字符串 - 上次我使用 CI(回到 1.7.x)时,它忽略了它们。尝试打开它们:

$config['enable_query_strings'] = true;

【讨论】:

    【解决方案2】:

    我相信您必须使用 $this->input->get() 来访问查询字符串,根据您的示例,该字符串会产生:

    array(1) { ["search_query"]=> string(4) "data" }
    

    另外,值得加入这个from the documentation

    请注意:如果您使用查询字符串,则必须构建自己的 URL,而不是使用 URL 帮助程序(以及生成 URL 的其他帮助程序,例如某些表单帮助程序),因为这些帮助程序旨在与分段一起使用基于 URL。

    【讨论】:

    • 问题是我不需要获取$_GET 数据,而是获取url,所以我用它来更改语言参数。
    • @w0rldart:我明白,但正如我所提到的,我认为获取查询字符串的唯一方法是使用$this->input->get()。我认为您必须将其与 uri_string 结合使用来构建“完整” URL。
    • 我有点需要uri_string 才能工作,因为 url 结构并不总是相同
    • @w0rldart:我理解你的困境,但uri_string 根本不包含查询字符串数据。要获取查询字符串,您必须使用$this->input->get()$_SERVER['QUERY_STRING'] 并自己构建完整的URL。 Please see the accepted answer to this question 获取有关创建帮助函数的建议。
    【解决方案3】:

    我在application/core/MY_Lang.php 中添加了这个我需要获得正确路径的地方:

    if(preg_match('/results/', $this->uri))
    {
        $this->uri = $this->uri.'?'.$_SERVER['QUERY_STRING'];
    }
    

    下面:$this->uri = $URI->uri_string();

    【讨论】:

      猜你喜欢
      • 2013-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 1970-01-01
      • 2013-07-07
      相关资源
      最近更新 更多