Skip to content

Commit

Permalink
adding controller mapping in resources ref #10423
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisShick committed Apr 5, 2017
1 parent 0a5c9eb commit c82aaa9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/Routing/RouteBuilder.php
Expand Up @@ -324,6 +324,7 @@ public function resources($name, $options = [], $callback = null)
'actions' => [],
'map' => [],
'prefix' => null,
'controller' => $name
];

foreach ($options['map'] as $k => $mapped) {
Expand Down Expand Up @@ -365,7 +366,7 @@ public function resources($name, $options = [], $callback = null)

$url = '/' . implode('/', array_filter([$urlName, $params['path']]));
$params = [
'controller' => $name,
'controller' => $options['controller'],
'action' => $action,
'_method' => $params['method'],
];
Expand Down
13 changes: 13 additions & 0 deletions tests/TestCase/Routing/RouteBuilderTest.php
Expand Up @@ -408,6 +408,19 @@ public function testResources()
$this->assertEquals('Articles', $all[0]->defaults['controller']);
}

/**
* Test connecting resources with a controller
*
* @return void
*/
public function testResourcesController()
{
$routes = new RouteBuilder($this->collection, '/api');
$routes->resources('Articles', ['controller' => 'Posts']);
$all = $this->collection->routes();
$this->assertEquals('Posts', $all[0]->defaults['controller']);
}

/**
* Test connecting resources with a prefix
*
Expand Down

0 comments on commit c82aaa9

Please sign in to comment.