phpcodeigniter-3friendly-urlurl-parsing

What does CodeIgniter's $this->uri->segment() method do?


Can someone please explain $this->uri->segment(3); to me?

What is its use and relevance in CodeIgniter?


Solution

  • The $this->uri->segment(n); is used to get some parts of the url which in some situations can be really handy. One of them could be:

    if you have an url like this:

    http://example.com/users/profile/1
    

    You could do:

    $this->uri->segment(3); //the third segment starting from /users so counting begin after the domain name
    

    in order to get the passed profile id and use this in your controller or model