Append / to the start/end of the mapResources prefix.

This makes the method easier to use and less error prone.

Fixes #2431
This commit is contained in:
mark_story 2013-12-04 21:46:59 -05:00
parent 58317d312c
commit 85a9132c9b
2 changed files with 20 additions and 0 deletions

View file

@ -503,6 +503,12 @@ class Router {
), $options);
$prefix = $options['prefix'];
if (strpos($prefix, '/') !== 0) {
$prefix = '/' . $prefix;
}
if (substr($prefix, -1) !== '/') {
$prefix .= '/';
}
foreach ((array)$controller as $name) {
list($plugin, $name) = pluginSplit($name);

View file

@ -215,6 +215,20 @@ class RouterTest extends CakeTestCase {
);
$this->assertEquals($expected, $result);
$this->assertEquals(array('test_plugin'), $resources);
$resources = Router::mapResources('Posts', array('prefix' => 'api'));
$_SERVER['REQUEST_METHOD'] = 'GET';
$result = Router::parse('/api/posts');
$expected = array(
'pass' => array(),
'named' => array(),
'plugin' => null,
'controller' => 'posts',
'action' => 'index',
'[method]' => 'GET'
);
$this->assertEquals($expected, $result);
}
/**