开发者

CodeIgniter - Get Last URI Segment

I'm trying to get the last URI segment in CI, how开发者_开发问答ever 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.

How can I tell CI to get the last segment?

Something like:

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


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


This should work:

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


I needed this in 2021 and here's how I got to it

$record_num = end($this->uri->segments)

Ty to Anpher that got me in the right track


Try this :

$last_segment = $this->uri->segment($this->uri->total_segments());
echo $last_segment;

Above code is for English language, for UTF8 such as Arabic, Persian, etc use :

$last_segment = $this->uri->segment($this->uri->total_segments());
echo urldecode($last_segment);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜