Hi,
I have found some post that describe the same problem that I have encountered:
Here is the list:
march 2007
fabruary 2007
january 2007 -1
january 2007 -2
The awaited parameters are missing in controler function when we use a target route with a folder in it?
a static example of route that doesn’t work:
$route['myroute'] = "folder/controler/methode/param1/param2";
//that return param2 as param1
and a complex one that doesn’t work:
$route['products/([a-z]+)/(\d+)'] = "folder/controler/methode/$1/id_$2";
//that return id_$2 in $1 place
Both work fine if we shouldn’t used controler into subfolder…..
I have seen that CI 1.5.3 is out since two days, I haven’t test it but I haven’t seen in the changelog any notes about fixing this problem??
Is it Fix in 1.5.3 ??
So I give you the result of my test:
1- Why this problem append:
Because CI use ‘rsegments’ that is returned by CI->uri->rsegment_array(); to find the parameters to be given to the function With the : $directory, $class and $method property of the CI_router classe.
But in the CI_router::_validate_segments() when CI set the $directory router property it unset the directory segment into the rsegment array.
Thus like there is a folder CI search the first param in $rsegments[4] and it is in the $rsegments[3] because the folder was unset.
Test a controler function with an optional param for that it not crash.
function testroute($param = "DEFAULT"){
echo "Param =".$param."</BR>";
echo "rsegments array: </br>".nl2br(print_r($this->uri->rsegment_array(),true));
}
Add in your route.php config:
$route['test1'] = "folder/controler/testroute/param1";
This output DEFAULT as param
$route['test2'] = "folder/controler/testroute/param1/param2";
And this output param2
And you will see that the folder is missing from the rsegments array
2- My Solution:
Some of you, in the post join at the begining, gived solution that toutch the CodeIgniter.php file, and if I have understand change the index awaited for the first parameter by shifting it of a notch on the left? I think 3 instaed of 4.
But as we work with a controler subfolder when we think about URI we wait for the first param at index 4. So my solution is to re-add the folder into the rsegment_array and all work as waited.
In the Router.php system libraries files, in the _compile_segments() methode
At the end of the methode juste before the line $this->rsegments = $segments;
Add this 3 lines:
if($this->fetch_directory() != ''){
array_unshift($segments,str_replace("/","",$this->fetch_directory()) );
}
//just before
$this->rsegments = $segments;
}
Try it and tell me if that’s work for you????
