Uri segment not working in codeigniter

Updated at 29-Aug-2022, By samar

Uri segment not working in codeigniter

In this session, we’ll try our hand at solving the "Uri segment not working in codeigniter" puzzle by using the computer language.

Here we have an URI (http://example.com /category/codeigniter/20) and we have to get the last segment of URI which value is 20.

So we can get the last (which is at number 3) segment of URI using $this->uri->segment(3). Here we have three segments in this URL like category is at place 1, codeigniter is at place 2 and 20 is at place 3.

To get the category you have to pass 1, for codeigniter pass 2 and for 20 you have to pass the 3 to $this->uri->segment() method.

  • Example code to get the URI segment in codeigniter

    Here we have an URL and we can get the URL segments (category, codeigniter, 20) by passing the number to $this->uri->segment() method at which place they are exist.



    To get the vlaue of category


    To get the vlaue of codeigniter


    To get the value of 20 from URI


Back to code snippet queries related codeIgniter