How To Get URI Segments in CodeIgniter?

QuestionsCategory: CodeIgniterHow To Get URI Segments in CodeIgniter?
Rishab asked 6 months ago

I want To Get the Value Form URL Segments in CodeIgniter Php.
$this->uri->Segments() not Working.
How To Get URI Segments in CodeIgniter?

1 Answers
matrix Staff answered 6 months ago

In CodeIgniter we Fetch the URI Segments Like,

$this->uri->segment(n); 

// Here, n=1 for controller, n=2 for method, etc

Lets, Consider this example:

http://example.com/index.php/controller/action/1st-segment/2nd-segment

 

the Above example will return

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

 

source:

https://www.codeigniter.com/userguide3/libraries/uri.html

https://www.codeigniter.com/userguide2/libraries/uri.html