Skip to content

CodeIgniter URI Segments ?

This post is about codeigniter URI Segments, ci’s uri class is initialized automatically by the system. with the help of uri segments we an get values from the URL , just like GET[‘key’] method in core php here in codeigniter the key may be numbe or string(when you get uri segment as an associative array). the more usefully thing is we can get re-routed segments information also.

How to access uri segments

we can call uri’s class method segment(), any were to access uri segments, this method accepts two parameters, one is segment number and second parameter is default value and second parameter is optional.

For example if the URL is : https://arjunphp.com/cat/article/id/123

cat is the 1st segment, article is the 2nd segment, id is the 3rd segment and 123 is the fourth segment . You can access each segment using $this->uri->segment(n)

//  url : https://arjunphp.com/cat/article/id/123
$this->uri->segment(1); // controller - cat
$this->uri->segment(2); // action - article
$this->uri->segment(3); // 1stsegment - id
$this->uri->segment(4); // 2ndsegment - 123

to know more methods of uri class please visit ci official document.

I hope this tutorial helps you please don’t forget to give us your feedback in comments.

0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments