CodeIgniter Forums
getting the uri segments - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: getting the uri segments (/showthread.php?tid=24044)



getting the uri segments - El Forum - 10-29-2009

[eluser]basty_dread[/eluser]
Hello there. I am new to CI.
i was able to pass this uri segments to the address bar using a javascript.
ex: http://localhost/page/index.php/keywords/popup/one/this two/this is three/amps/four

my propblem is i want to echo the segments after /popup/ which is /one/,/this two/ and up to the last which is /four


i want to assign it to an array but i dont know how.
this values -----> /one/this two/this is three/amps/four
because i will insert it to my database.


im sorry for my english. i hope you all understand what i am talking about.
Thank you very much for anyone who will help.


getting the uri segments - El Forum - 10-29-2009

[eluser]rogierb[/eluser]
Did you read the userguide? The part about the "URI Class" might interest you.


getting the uri segments - El Forum - 10-29-2009

[eluser]basty_dread[/eluser]
ohhh... what could be the code for looping? and putting this values to an array?
thank you rogierb for posting.


getting the uri segments - El Forum - 10-29-2009

[eluser]rogierb[/eluser]
Read the user guide, they are already in an array.


getting the uri segments - El Forum - 10-29-2009

[eluser]daparky[/eluser]
$this->uri->segment(n)

Permits you to retrieve a specific segment. Where n is the segment number you wish to retrieve. Segments are numbered from left to right. For example, if your full URL is this:
http://example.com/index.php/news/local/metro/crime_is_up

The segment numbers would be this:

1. news
2. local
3. metro
4. crime_is_up

By default the function returns FALSE (boolean) if the segment does not exist. There is an optional second parameter that permits you to set your own default value if the segment is missing. For example, this would tell the function to return the number zero in the event of failure:
$product_id = $this->uri->segment(3, 0);


getting the uri segments - El Forum - 10-29-2009

[eluser]basty_dread[/eluser]
okey.. thank you very much Smile