Adding ability to specify named arguments in the URL

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@3115 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
nate 2006-06-15 15:51:34 +00:00
parent 79ba4fa94d
commit 0d707d4360
2 changed files with 42 additions and 1 deletions

View file

@ -192,8 +192,17 @@ class Dispatcher extends Object {
}
if (!empty($controller->params['pass'])) {
if ($controller->namedArgs !== false) {
if (is_array($controller->namedArgs) && in_array($params['action'], array_keys($controller->namedArgs))) {
$this->_getNamedArgs($controller->params['pass'], $controller->namedArgs[$params['action']]);
} elseif (is_int($controller->namedArgs) && $controller->namedArgs > 0) {
$this->_getNamedArgs($controller->params['pass'], $controller->namedArgs);
} elseif ($controller->namedArgs === true) {
$this->_getNamedArgs($controller->params['pass']);
}
}
$controller->passed_args =& $controller->params['pass'];
$controller->passedArgs =& $controller->params['pass'];
$controller->passedArgs =& $controller->params['pass'];
} else {
$controller->passed_args = null;
$controller->passedArgs = null;
@ -414,5 +423,31 @@ class Dispatcher extends Object {
}
return $params;
}
/**
* Enter description here...
*
* @param unknown_type $params
* @return unknown
*/
function _getNamedArgs(&$params, $start = 0) {
if(is_array($params)) {
$a = array();
$args = $params;
$c = count($args);
for ($l = $start; $l < $c; $l++) {
if(isset($args[$l])) {
if ($l+1 < count($args)) {
$a[$args[$l]] = $args[$l+1];
} else {
$a[$args[$l]] = null;
}
}
$l++;
}
$params = $a;
}
}
}
?>

View file

@ -200,6 +200,12 @@ class Controller extends Object{
* @var boolean
*/
var $persistModel = false;
/**
* Enter description here...
*
* @var mixed
*/
var $namedArgs = false;
/**
* Constructor.
*