jaysonic - 08 May 2011 07:31 AM
Another solution, which has been posted although it modifies all the segments, is as follows.
Create the MY_Router.php file in /application/core and in it place the following code:
<?php
public function _set_request($segments){
// Fix only the first 2 segments
for($i = 0; $i < 2; ++$i){
if(isset($segments[$i])){
$segments[$i] = str_replace('-', '_', $segments[$i]);
}
}
// Run the original _set_request method, passing it our updated segments.
parent::_set_request($segments);
}
?>
This just modifies the first 2 segments in your URL, but only if they are set. Hopefully that helps someone.
why don’t you just do
parent::_set_request( str_replace( '-', '_', $segments ) );
?
Anyway, this solution works only because CI is not written in true OOP manner. The code hasn’t completely been upgraded from the PHP 4 days. If you look at the source code of the CI_Router class, the _set_request function is supposed to have private access; that is, no other class—not even the classes that inherit from it—is supposed to access it or override it. If in the next release they decide to put “private” in front of it, then your upgrade will not be easy, especially if this is not the only modification of this kind.
I know, a little late, but I suggest the hooks method.