Browse Source

Fix named routes not being indexed for reverse routing.

While *generally* people will be using the named route, we also need to
store routes based on their normal name. This allows features like
PaginatorHelper to interact with custom routes.

Refs #4126
mark_story 11 years ago
parent
commit
23077613b4

+ 0 - 5
src/Routing/Route/Route.php

@@ -90,8 +90,6 @@ class Route {
  *
  * ### Options
  *
- * - `_name` - By using $options['_name'] a specific name can be
- *   given to a route. Otherwise a route name will be generated.
  * - `_ext` - Defines the extensions used for this route.
  * - `pass` - Copies the listed parameters into params['pass'].
  *
@@ -103,9 +101,6 @@ class Route {
 		$this->template = $template;
 		$this->defaults = (array)$defaults;
 		$this->options = $options;
-		if (isset($this->options['_name'])) {
-			$this->_name = $this->options['_name'];
-		}
 		if (isset($this->defaults['[method]'])) {
 			$this->defaults['_method'] = $this->defaults['[method]'];
 			unset($this->defaults['[method]']);

+ 1 - 1
tests/TestCase/Routing/Route/RouteTest.php

@@ -888,7 +888,7 @@ class RouteTest extends TestCase {
  */
 	public function testGetName() {
 		$route = new Route('/foo/bar', array(), array('_name' => 'testing'));
-		$this->assertEquals('testing', $route->getName());
+		$this->assertEquals('', $route->getName());
 
 		$route = new Route('/:controller/:action');
 		$this->assertEquals('_controller:_action', $route->getName());

+ 3 - 0
tests/TestCase/Routing/RouteCollectionTest.php

@@ -183,6 +183,9 @@ class RouteCollectionTest extends TestCase {
 
 		$result = $this->collection->match(['_name' => 'article:view', 'id' => '2'], $context);
 		$this->assertEquals('/b/2', $result);
+
+		$result = $this->collection->match(['plugin' => null, 'controller' => 'Articles', 'action' => 'view', 'id' => '2'], $context);
+		$this->assertEquals('b/2', $result);
 	}
 
 /**