【问题标题】:Code Igniter - Get Before Last URI SegmentCodeigniter - 在最后一个 URI 段之前获取
【发布时间】:2012-03-02 12:45:44
【问题描述】:

我在stackOverflow上发现我得到的最后一段可以这样找到:

end($this->uri->segment_array());

上面的语句有一个变通方法来获取最后一段之前的部分吗?

我不是在问

$this->uri->uri_to_assoc(n)

$this->uri->segment(n)

谢谢。

【问题讨论】:

  • 两个答案都有效,但我更喜欢@Jordan 的答案。我的选择!谢谢你们。

标签: codeigniter uri segment


【解决方案1】:

这是之前的片段。

$secondLastKey = count($this->uri->segment_array())-1;
$this->uri->segment($secondLastKey);

【讨论】:

  • 其实我只需要最后一个和最后一个。我在 URL 中从 jQuery 传递了变量。谢谢。
  • 这里给出了最后一个。最后一个由您描述的 end() 函数给出。如果需要,将两者与连接运算符 (.) 合并在一起。
【解决方案2】:
$segs = $this->uri->segment_array();
$number = count($segs)-2;
echo $segs[$number];

【讨论】:

    【解决方案3】:
    $last = $this->uri->segment($this->uri->total_segments());
    $beforelast = $this->uri->segment($last--);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-09
      • 2011-05-02
      • 2016-12-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-10
      相关资源
      最近更新 更多