Question Detail

How can I get Url Segment from the URL in CodeIgniter I have tried many ways but not succeeded Please tell me the exact code how to get URI segment? 


Thread Reply

Bili Greed

- 1 years ago

This provides you to retrieve information from your URI strings

$this->uri->segment(n); // n=1 for controller, n=2 for method, etc

consider this example http://example.com/index.php/controller/action/1stsegment/2ndsegment

it will return

$this->uri->segment(1); // controller
$this->uri->segment(2); // action
$this->uri->segment(3); // 1stsegment
$this->uri->segment(4); // 2ndsegment