CodeIgniter Forums
$this->uri->segment(#) not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: $this->uri->segment(#) not working (/thread-26780.html)



$this->uri->segment(#) not working - El Forum - 01-22-2010

[eluser]JayArias[/eluser]
I am trying to retrieve /people/USERNAME. But for some reason I get a 404 Error when requesting the segment.

Code:
$this->uri->segment(3)

I've tried ROUTES, and everything nothing works.


$this->uri->segment(#) not working - El Forum - 01-22-2010

[eluser]bretticus[/eluser]
[quote author="JayArias" date="1264231779"]I am trying to retrieve /people/USERNAME. But for some reason I get a 404 Error when requesting the segment.

Code:
$this->uri->segment(3)
[/quote]

You get a 404 only when you call $this->uri->segment(3) in your code?? That doesn't make sense. Is people your controller or a controller method? From the looks of your URL, it's your controller. Since the 2nd segment is typically reserved for your action/function/method, I doubt that you have methods for each username. Perhaps, you need to access the method? ie.

/people/person/USERNAME assuming you name your method "person."

Yes, routes would be perfect for this scenario if you want to drop the method from the URL. What have you tried thus far?


$this->uri->segment(#) not working - El Forum - 01-22-2010

[eluser]brandon.cordell[/eluser]
How do you have your project set up?

404 Error means the page you requested wasn't found. If you type http://google.com/this-does-not-exist.phtml
into your browser, you will get a 404 error. $this->uri->segment() just returns part of the current URI string.


$this->uri->segment(#) not working - El Forum - 01-22-2010

[eluser]vitoco[/eluser]
USERNAME is the 3rd or the 2nd segment, cause the structure is /controller/method/param1/.../paramN , so when you call /people/USERNAME , you're assuming that there is a method or function called USERNAME.

The "correct" way to call can be /people/profile/USERNAME or /people/data/USERNAME.