laravel/laravel — Issue #352: Bug autoloading controllers
Author: lomboo
Created: 2012-02-21 15:29:25+00:00
State: open

Check the docs of the ```Autoloader::controller``` method. If the method is called with User_Profile_Controller it should return user/profile.

Instead, it returns user/profile/controller. This is caused by the order in the array in str_replace.

str_replace docs state

> If search and replace are arrays, then str_replace() takes a value from each array and uses them to search and replace on subject

The order of the arrays should be reversed, instead of ```str_replace(array('_', '_Controller'), array('/', ''), $class)``` it should be ```str_replace(array('_Controller', '_'), array('', '/'), $class)```

```
/**
* Translate a given controller class name into the corresponding file name.
*
* The controller suffix will be removed, and the underscores will be translated
* into directory slashes. Of course, the entire class name will be converted to
* lower case as well.
*
*
*	// Returns "user/profile"...
*	$file = static::controller('User_Profile_Controller');
*
*
* @param string $class
* @return string
*/
protected static function controller($class)
{
$controller = str_replace(array('_', '_Controller'), array('/', ''), $class);

return CONTROLLER_PATH.strtolower($controller).EXT;
}
```