代码点火器 - 获取上一个URI段

Rob*_*imp 14 php codeigniter

我想要在CI中获取最后一个URI段,但是我不知道它的数量是多少,因为当用户点击页面中的链接时,将附加参数(整数).然后在控制器中使用它们通过ajax将相关的数据库记录拉入页面.

如何告诉CI获取最后一段?

就像是:

$record_num = $this->uri->segment($last);
Run Code Online (Sandbox Code Playgroud)

谢谢!

Anp*_*her 34

$record_num = end($this->uri->segment_array());
Run Code Online (Sandbox Code Playgroud)

  • `只有变量应该通过引用传递`。请改用 Mischa 答案。 (2认同)

Mis*_*cha 28

这应该工作:

$last = $this->uri->total_segments();
$record_num = $this->uri->segment($last);
Run Code Online (Sandbox Code Playgroud)