views:

67

answers:

2

Hello,

I'm tying 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.

How can I tell CI to get the last segment?

Something like:

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

Thanks!

+3  A: 

This should work:

$last = $this->uri->total_segments();
$record_num = $this->uri->segment($last);
captaintokyo
+1 I like this method better, since it uses codeigniter's functionality. It just seems like the right thing to do.
Matthew
I agree, like this one better. You can save yourself a line too: $record_num = $this->uri->segment($this->uri->total_segments());
Mitchell McKenna
+5  A: 
$record_num = end($this->uri->segment_array());
Anpher