Skip to content
Permalink
Browse files

Add a simple oneliner way to add fallback routes to a scope.

I found I was repeating these same 2 lines in many places. Having
a simple macro for them will make working with routes a bit less
repetitive.
  • Loading branch information...
markstory committed Jul 3, 2014
1 parent 99d8d42 commit 9d9453a1279a9273c6402179c38e6297b784e7d3
Showing with 26 additions and 0 deletions.
  1. +12 −0 src/Routing/ScopedRouteCollection.php
  2. +14 −0 tests/TestCase/Routing/ScopedRouteCollectionTest.php
@@ -626,4 +626,16 @@ public function merge(ScopedRouteCollection $collection) {
$this->_named += $collection->named();
}
/**
* Connect the `/:controller` and `/:controller/:action/*` fallback routes.
*
* This is a shortcut method for connecting fallback routes in a given scope.
*
* @return void
*/
public function fallbacks() {
$this->connect('/:controller');
$this->connect('/:controller/:action/*');
}
}
@@ -379,4 +379,18 @@ public function testResourcesNested() {
});
}
/**
* Test connecting fallback routes.
*
* @return void
*/
public function testFallbacks() {
$routes = new ScopedRouteCollection('/api', ['prefix' => 'api']);
$routes->fallbacks();
$all = $routes->routes();
$this->assertEquals('/api/:controller', $all[0]->template);
$this->assertEquals('/api/:controller/:action/*', $all[1]->template);
}
}

0 comments on commit 9d9453a

Please sign in to comment.
You can’t perform that action at this time.