Welcome Guest, Not a member yet? Register   Sign In
Bug for routing sub-foldered controller [includes patch]
#1

[eluser]Unknown[/eluser]
Hi everybody,

I came upon this bug while developing a branch of my application for facebook and needed to put my facebook controllers in a subfolder.

The problem is with Router segments array, in my case it looks like this:

1)"raw" segments (before parsing routes), "facebook" is my sub-folder
Code:
array(4) { [0]=> string(8) "facebook" [1]=> string(11) "<CLASS>" [2]=> string(5) "<METHOD>" [3]=> string(7) "<PARAM>" }

2) routed segments ($Router->rsegments)
Code:
array(3) { [0]=>  string(11) "<CLASS>" [1]=>  string(5) "<METHOD>" [2]=>  string(7) "<PARAM>" }

and surprisingly the first one is served in the end, so it looks like routing didn't happen..


In Router.php there's a method _reindex_segments() (line 252) where you check :
Code:
array_diff($this->rsegments, $this->segments)

And here's the bug.. even though on php.net (http://pl.php.net/manual/en/function.array-diff.php) they say that array_diff "Compares array1 against array2 and returns the difference." it doesn't work like this.. instead it returns an array containing all the values of array1 that are not present in any of the other arguments.


So in my case your check returns $diff = false even if arrays are different.


My patch looks like this :
Code:
$diff = (count(array_diff($this->rsegments, $this->segments)) == 0 && count(array_diff($this->segments, $this->rsegments)) == 0) ? FALSE : TRUE;


And it works perfectly like this Smile

Best,
Andrzej


Messages In This Thread
Bug for routing sub-foldered controller [includes patch] - by El Forum - 10-25-2007, 09:55 AM



Theme © iAndrew 2016 - Forum software by © MyBB