【问题标题】:Get the value from URL从 URL 获取值
【发布时间】:2016-02-17 20:11:54
【问题描述】:

在这个网址:www.example.com/transaction/summary/10 我可以通过这个得到10

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

但是,与其他一些 GET 参数一起,我怎样才能获得该值?

例如:www.example.com/transaction/summary?local_branch=1/10

PS:GET 参数可能大于 1。

【问题讨论】:

标签: php codeigniter url


【解决方案1】:

如果您仍想保持CI 样式而不是添加细分:

网址:

www.example.com/transaction/summary/10/1/TEST

细分:

$this->uri->segment(3); // 10
$this->uri->segment(4); // 1
$this->uri->segment(5); // TEST

或者,如果您想使用查询字符串,则可以在查询字符串中添加参数并使用 $_GET 获取值:

www.example.com/transaction/summary/10/?local_branch=1&test=test

【讨论】:

    【解决方案2】:

    好的,Codeigniter 中的段是斜线之间的内容,例如 mysite.com/page/page-name。为了获得页面名称值,我获得了第二段,或$this->uri->segment(1)。要获取查询字符串 ($_GET) 传递的字符串,您可以简单地使用 $_GET['local_branch'] (如在您的示例中或在 Codeigniter 的情况下)作为 @Tom 答案:$this->input->get('local_branch')

    在这种情况下,您可以分解由 / 分隔的值。

    $localBranch = $_GET['local_branch'];
    
    // Or
    $localBranch = $this->input->get('local_branch');
    
    // And split using the / as delimiter if is need.
    $localBranch = explode('/', $localBranch);
    
    // Output
    // Array(0 => 1, 1 => 10)
    

    这样可以在同一个查询字符串中传递多个值。

    【讨论】:

      【解决方案3】:

      要获取这些 GET 参数,您可以使用:

      $this->input->get('some_variable', TRUE);

      这里的SO link

      example.com/?some_variable=hey

      【讨论】:

      • 您的链接显示“文档”,但它只是指向另一个 SO 答案的链接,其中包含文档的实际链接。
      • 你没有回复答案
      猜你喜欢
      • 2012-03-28
      • 2016-09-23
      • 1970-01-01
      • 2011-03-04
      • 2012-10-31
      • 2013-05-06
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多