1
votes

i have the following URI:

    http://mysite/myapp/index.php/test/testURL/CAN-q1/300-48/fa1/59//can-a2

You'll notice that the 7th URI segment is not set. I need to test for these types of scenarios.
I've tried a few different things but i can't seem to get it to work. What's happening is segment 8 is being assigned as segment 7. Here's some test code I've been playing with this morning:

    echo '3 - '. $this->uri->segment(3); 
    echo '<BR>';
    echo '4 - '. $this->uri->segment(4); 
    echo '5 - '. $this->uri->segment(5); 
    echo '<BR>';
    echo '6 - '.$this->uri->segment(6);
    echo '<BR>';
    $test = $this->uri->segment(7,0);   
    echo '7 is: '.$test;
    echo '<BR>';
    echo '8 - '. $this->uri->segment(8);
    echo '<BR>';

And the results come back as:

 3 - CAN-q1
 4 - 300-48
 5 - fa1
 6 - 59
 7 is: can-a2
 8 - 

Based on reading the codeigniter manual, i would have expected that segment 7 would contain a 0 or whatever i passed as the second parameter in the uri->segment() method.

Can you tell me where I'm going wrong? Thanks.

1
Is this not the web browser itself ignoring empty segments? stackoverflow.com/questions/13881707//////… <<< this still leads to this thread regardless of how many slashes you put in, I don't think you can have empty segments and expect CI to read them as part of the order and I do think that is web browsers in general and not CI specific. - Rick Calder
I think you'll find it is your browser - not CI. I cant remember where I read it, but I've come across this before. Your only option is to either enable query strings, or always pass something for the variable (perhaps "0" to mean false) - Laurence
thanks everyone. you guys all gave me the same idea... does someone want to post it as an answer? - dot
@dot you could post the answer yourself and accept it. - Kinjal Dixit

1 Answers

1
votes

I just decided to pass a space instead of an empty URI, based on comments that others have made that you can't have a empty segment. This seems to have resolved the problem. Thanks to everyone who commented.