Ticket Details

Route parameter formatting not configurable

RFC Ticket (closed)

###What happened:
I placed the following into ```config/routes.php```:

{{{
Router::connect('/hello-world', array('controller' => 'app\controllers\HelloWorldController', 'action' => 'index'));
}}}

What I received when attempting to load ```/hello-world``` was:

{{{
Exception: Controller App\controllers\HelloWorldController not found in /path/to/libraries/lithium/action/Dispatcher.php on line 134
}}}

###What was expected:
I expected Lithium to be able to find the controller class specified. In order to fix this, though, I had to add the back slash (```\```) to the beginning of the full class name, like this:

{{{
Router::connect('/hello-world', array('controller' => '\app\controllers\HelloWorldController', 'action' => 'index'));
}}}

The reason I see this requirement as a problem is because the manual at PHP.net has established the convention in its [namespace documentation](http://php.net/namespaces) of using the back slash (```\```) at the beginning of the fully qualified class name only in cases when calling functions or classes in the global space (built-in, internal classes/functions), while fully qualified class names in the user space do not begin with the back slash.

Because of this convention established by the manual, users will likely not think to include the back slash at the beginning of their user space controller names.
on 12.30.09 reported by: ramsey owned by: nate

Updates

on 12.30.09 by ramsey
  • description was changed
on 12.30.09 by nate
  • type was changed to rfc
  • priority was changed to normal
  • title was changed to Route parameter formatting not configurable
on 12.30.09 by nate
Changing this to an RFC until we can come up with a fix for making route parameter formatting configurable, i.e.: `/hello-world` mapping to `HelloWorldController`.
(works-for-me) on 05.04.10 by nate
  • owner was changed to nate
  • status was changed to closed
  • resolution was changed to works-for-me
This has mostly been addressed in prior versions. To handle hyphen-formatted controller / action names, implement the following in `app/config/bootstrap/action.php`:

{{{
Dispatcher::applyFilter('_callable', function($self, $params, $chain) {
	$routeParams = $params['params'];
	foreach (array('action', 'controller') as $key) {
		$routeParams[$key] = str_replace('-', '_', $routeParams[$key]);
	}
	$params['params'] = $routeParams['action'];
	return $chain->next($self, $params, $chain);
});
}}}

If anyone has any other comments or suggestions, please add them to this ticket.