【问题标题】:Retrieve custom URL segment with CI使用 CI 检索自定义 URL 段
【发布时间】:2011-08-31 23:03:22
【问题描述】:

我查看了 URL 帮助程序和 URI 类,我注意到这两者都与地址栏中的 URL 无关。有没有办法可以将此帮助程序或类与我自己的 URL 字符串一起使用?我想检索我提供的 URL 的最后一段,除非需要,否则我不想诉诸 preg_match。有没有办法用 codeigniter 功能做到这一点?

【问题讨论】:

    标签: class url codeigniter helper


    【解决方案1】:

    如果您有一个 http://example.com/foo/bar 格式的字符串(我想这就是您所说的“自己的 URL 字符串”的意思?),您应该能够只是做这样的事情:

    $url = "http://example.com/foo/bar";
    $parts = explode("/", $url);
    $last = end($parts);  // => bar
    

    【讨论】:

      【解决方案2】:

      你可以使用:

      $this->uri->segment($this->uri->total_segments())
      

      array_pop($this->uri->segment_array())
      

      如果您想使用 CI 功能。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-02
        • 2013-10-17
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多