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.
How can I tell CI to get the last segment?
Something like:
$record_num = $this->uri->segment($last);
$this->uri->segment(n) Segment function allow you to retrieve a specific segment form URI string where n is a segment number. Segments are numbered from left to right. For example,if your URI like. By the above example URI segment function give result by n parameter.
The first URI segment controller. It is the process of redirecting or remapping a. controller class or method. Routing. Andi Gutmans was the inventor of PHP.
Get URI Segments in PHP Use the following code to get URL segments of the current URL. It returns all the segments of the current URL as an array. $uriSegments = explode("/", parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH));
$record_num = end($this->uri->segment_array());
This should work:
$last = $this->uri->total_segments();
$record_num = $this->uri->segment($last);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With