mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
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:
parent
58317d312c
commit
85a9132c9b
2 changed files with 20 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue