php CodeIgniter - 获取最后一个 URI 段

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3829781/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 11:14:53  来源:igfitidea点击:

CodeIgniter - Get Last URI Segment

phpcodeigniter

提问by Robimp

I'm trying to get the last URI segment in CI, however I don't know what the number for it will be, as parameters (an integer) will be appended as the user clicks links within the page. These are then used in a controller to pull relevant database records into the page via ajax.

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

How can I tell CI to get the last segment?

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

Something like:

就像是:

$record_num = $this->uri->segment($last);

回答by Anpher

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

回答by Mischa

This should work:

这应该有效:

$last = $this->uri->total_segments();
$record_num = $this->uri->segment($last);