Fixed problem with boolean values passed into connectNamed

Added documentation


git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@6934 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
the_undefined 2008-05-18 23:08:49 +00:00
parent 847811701c
commit 521986b27f
2 changed files with 28 additions and 4 deletions

View file

@ -220,10 +220,28 @@ class Router extends Object {
return $_this->routes; return $_this->routes;
} }
/** /**
* Connects an array of named arguments (with optional scoping options) *Specifies what named parameters CakePHP should be parsing. The most common setups are:
*
* Do not parse any named parameters:
* Router::connectNamed(false);
*
* Parse only default parameters used for CakePHP's pagination:
* Router::connectNamed(false, array('default' => true));
*
* Parse only the page parameter if its value is a number:
* Router::connectNamed(array('page' => '[\d]+'), array('default' => false, 'greedy' => false));
*
* Parse only the page parameter no mater what.
* Router::connectNamed(array('page'), array('default' => false, 'greedy' => false));
*
* Parse only the page parameter if the current action is 'index'.
* Router::connectNamed(array('page' => array('action' => 'index')), array('default' => false, 'greedy' => false));
* *
* @param array $named List of named arguments * Parse only the page parameter if the current action is 'index' and the controller is 'pages'.
* @param array $options Named argument handling options * Router::connectNamed(array('page' => array('action' => 'index', 'controller' => 'pages')), array('default' => false, 'greedy' => false));
*
* @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
* @access public * @access public
* @static * @static
*/ */
@ -234,7 +252,7 @@ class Router extends Object {
unset($options['argSeparator']); unset($options['argSeparator']);
} }
if ($named === true || $named === false) { if ($named === true || $named === false) {
$options = array('default' => $named, 'reset' => true, 'greedy' => $named); $options = array_merge(array('default' => $named, 'reset' => true, 'greedy' => $named), $options);
$named = array(); $named = array();
} }
$options = array_merge(array('default' => false, 'reset' => false, 'greedy' => true), $options); $options = array_merge(array('default' => false, 'reset' => false, 'greedy' => true), $options);

View file

@ -905,6 +905,12 @@ class RouterTest extends UnitTestCase {
ini_set('arg_separator.output', $restore); ini_set('arg_separator.output', $restore);
} }
function testConnectNamed() {
$named = Router::connectNamed(false, array('default' => true));
$this->assertFalse($named['greedy']);
$this->assertEqual(array_keys($named['rules']), $named['default']);
}
function testNamedArgsUrlGeneration() { function testNamedArgsUrlGeneration() {
$result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 1, 'deleted' => 1)); $result = Router::url(array('controller' => 'posts', 'action' => 'index', 'published' => 1, 'deleted' => 1));
$expected = '/posts/index/published:1/deleted:1'; $expected = '/posts/index/published:1/deleted:1';