【问题标题】:Codeigniter Routes having GET variables具有 GET 变量的 Codeigniter 路由
【发布时间】:2014-04-18 04:28:29
【问题描述】:

我正在尝试使用路由来重定向具有 GET 变量的 URL,如下所示:

$route['^(beautified-link)'] = "controller/function?param=6";

但它没有考虑它..请建议

【问题讨论】:

标签: php codeigniter routes


【解决方案1】:

我不确定这点,但您可以通过更改配置文件中的这些值来尝试一下。

$config['uri_protocol'] = "PATH_INFO"; 
$config['enable_query_strings'] = TRUE; 

并尝试访问像

这样的 url
$this->input->get(‘param’);

【讨论】:

  • @akhil.. 在函数参数的情况下.. bt 在我的情况下,它是一个 GET 变量,通常被称为:site.com/controller/function?param=6跨度>
  • @akhil.. 非常感谢.. bt 它没有 :( 我不得不更改我的代码以将 GET 变量作为 codeigniter 函数参数发送并将路由用作:$route['^(beautified-link)'] = "controller/function/6";
【解决方案2】:
$route['^(beautified-link)'] = "controller/function";

我认为只需要指定控制器和方法就可以了,不需要维护传递GET变量的路由。

【讨论】:

    【解决方案3】:

    为什么要使用获取参数?

    在 config/autoload.php 中自动加载 url 助手

    $autoload['helper'] = array('url');
    

    你可以使用类似的网址

    http://example.com/controller/function/param

    param 可以是数字、字符串或任何你想要的东西

    在控制器中你可以用这个来读取参数

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

    $var=$this->uri->segment(4);//depend of number of "/" that you put on the url
    

    【讨论】:

      【解决方案4】:

      您需要在配置文件中启用您的查询字符串。

      $config['enable_query_strings'] = TRUE; 
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多