slashes, segments and paths |
[eluser]mrahman[/eluser]
Hi, I have a controller function that accepts a paramets as a path. now i consider the uri segments starting from 2 until the end is the path: Code: $myPath=array_slice($this->uri->segment_array(),2)) this is wrong and i'm mistaken, simply because what if i need to pass another segment? well. how can i pass a path to the uri without breaking it? i could if i get $_GET working. i searched the forum and now i want to avoid _$GET. any clues? edit: CI recognizes controller/method as the 1st/2nd segments. CI handles that, and now i have the method called, regardless of the next segments.
[eluser]Chris Newton[/eluser]
You can use uri_to_assoc to pass as many name/value pairs as you'd like and access them by their name, rather than their segment value. That way you don't have to worry about the order, or amount of variables you're passing. http://ellislab.com/codeigniter/user-gui...s/uri.html Additionally, I created a small getter / setter for the URI to make it simpler; http://codeigniter.com/wiki/URI_helper/ I always preferred passing stuff with query strings because it was so simple. Using uri_to_assoc kinda replicates that simplicity. Alternately, you could pass & retrieve information through POST http://ellislab.com/codeigniter/user-gui...input.html
[eluser]mrahman[/eluser]
Thanks. I also checked your helper at wiki. I use uri_to_assoc so often and it's really helpful. a great replacement for our old friend, $_GET. The problem is that, i got no way to know the length of segments that represents a path. A path may consist of one segment and up to any number. for example, to pass this path documents/pdf/tutorial.pdf: http://site/index.php/controller/method/...torial.pdf now, controller->method() will execute, an within it i can get the requested path, by combining the segments. if i use something like controller/method/path/documents/pdf/tutorial.pdf and used uri_to_assoc, i will have like array('path'=>'documents','pdf'=>'tutorial.pdf') and that makes me feel like revolving in a circle.
[eluser]Chris Newton[/eluser]
I see. So just pass this information as post, instead of through the URI. OR you could precede the string with a number representing the number of segments to look for and do a foreach on the segments based on your number to build the link in your controller. http://site/index.php/controller/method/...torial.pdf http://site/index.php/controller/method/...torial.pdf http://site/index.php/controller/method/...torial.pdf Post sounds easier though.
[eluser]mrahman[/eluser]
I would have used Post from the start but it was never an option. but you inspired me. I can pass as many segments, as long as the path is the last one. thanks :-) |
Welcome Guest, Not a member yet? Register Sign In |