diff --git a/cake/libs/router.php b/cake/libs/router.php index 8d76a7ba5..29e38dc3a 100644 --- a/cake/libs/router.php +++ b/cake/libs/router.php @@ -89,7 +89,7 @@ class Router { * @access public */ public static $named = array( - 'default' => array(':page', ':fields', ':order', ':limit', ':recursive', ':sort', ':direction', ':step'), + 'default' => array('page', 'fields', 'order', 'limit', 'recursive', 'sort', 'direction', 'step'), 'greedy' => true, 'separator' => ':', 'rules' => false, @@ -316,7 +316,7 @@ class Router { * * {{{ Router::connectNamed(array('page' => '[\d]+'), array('default' => false, 'greedy' => false)); }}} * - * Parse only the page parameter no mater what. + * Parse only the page parameter no matter what. * * {{{ Router::connectNamed(array('page'), array('default' => false, 'greedy' => false)); }}} * @@ -338,15 +338,23 @@ class Router { * ); * }}} * + * ### Options + * + * - `greedy` Setting this to true will make Router parse all named params. Setting it to false will + * parse only the connected named params. + * - `default` Set this to true to merge in the default set of named parameters. + * - `reset` Set to true to clear existing rules and start fresh. + * - `separator` Change the string used to separate the key & value in a named parameter. Defaults to `:` + * * @param array $named A list of named parameters. Key value pairs are accepted where values are * either regex strings to match, or arrays as seen above. * @param array $options Allows to control all settings: separator, greedy, reset, default * @return array */ public static function connectNamed($named, $options = array()) { - if (isset($options['argSeparator'])) { - self::$named['separator'] = $options['argSeparator']; - unset($options['argSeparator']); + if (isset($options['separator'])) { + self::$named['separator'] = $options['separator']; + unset($options['separator']); } if ($named === true || $named === false) { diff --git a/cake/tests/cases/libs/router.test.php b/cake/tests/cases/libs/router.test.php index d9a57afc8..c44f27619 100644 --- a/cake/tests/cases/libs/router.test.php +++ b/cake/tests/cases/libs/router.test.php @@ -1335,14 +1335,14 @@ class RouterTest extends CakeTestCase { Router::reload(); Router::connect('/foo/*', array('controller' => 'bar', 'action' => 'fubar')); - Router::connectNamed(array(), array('argSeparator' => '=')); + Router::connectNamed(array(), array('separator' => '=')); $result = Router::parse('/foo/param1=value1/param2=value2'); $expected = array('pass' => array(), 'named' => array('param1' => 'value1', 'param2' => 'value2'), 'controller' => 'bar', 'action' => 'fubar', 'plugin' => null); $this->assertEqual($result, $expected); Router::reload(); Router::connect('/controller/action/*', array('controller' => 'controller', 'action' => 'action'), array('named' => array('param1' => 'value[\d]'))); - Router::connectNamed(array(), array('greedy' => false, 'argSeparator' => '=')); + Router::connectNamed(array(), array('greedy' => false, 'separator' => '=')); $result = Router::parse('/controller/action/param1=value1/param2=value2'); $expected = array('pass' => array('param2=value2'), 'named' => array('param1' => 'value1'), 'controller' => 'controller', 'action' => 'action', 'plugin' => null); $this->assertEqual($result, $expected);