adding router fix for array params, ticket #1824, removing ternary operator from HtmlHelper::link();

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4228 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2006-12-29 04:16:53 +00:00
parent 8b79b227cc
commit ed28c3187b
2 changed files with 18 additions and 35 deletions

View file

@ -423,7 +423,7 @@ class Router extends Overloadable {
for ($i = 0; $i < $count; $i++) {
if (is_numeric($keys[$i]) || $keys[$i] == 'id') {
$args[] = $url[$keys[$i]];
} else if(!empty($path['namedArgs']) && in_array($keys[$i], array_keys($path['namedArgs']))){
} else if(is_array($path['namedArgs']) && in_array($keys[$i], array_keys($path['namedArgs']))){
$named[] = array($keys[$i], $url[$keys[$i]]);
} else if ($match === false) {
$args[] = $keys[$i] . $path['argSeparator'] .$url[$keys[$i]];
@ -435,17 +435,15 @@ class Router extends Overloadable {
}
}
$combined = '';
if (!empty($path['namedArgs'])) {
$count = count($named);
for ($i = 0; $i < $count; $i++) {
$named[$i] = join($path['argSeparator'], $named[$i]);
}
$combined = join('/', $named);
$named = join('/', $named);
}
if ($match === false) {
$urlOut = array_filter(array($url['plugin'], $url['controller'], $url['action'], join('/', array_filter($args)), $combined));
$urlOut = array_filter(array($url['plugin'], $url['controller'], $url['action'], join('/', array_filter($args)), $named));
if($url['plugin'] == $url['controller']) {
array_shift($urlOut);
}
@ -453,8 +451,8 @@ class Router extends Overloadable {
array_unshift($urlOut, CAKE_ADMIN);
}
$output = join('/', $urlOut);
} elseif (!empty($combined)) {
$output .= $combined;
} else if (!empty($named)) {
$output .= $named;
}
$output = $base . '/' . $output;
} else {
@ -491,12 +489,6 @@ class Router extends Overloadable {
$defaults = am(array('controller'=> null, 'plugin' => null), $route[3]);
$required = array_diff_key($defaults, $params);
$url = am(array('controller'=> null,'action' => 'index', 'plugin' => null), $url);
// $url = am($required, $url);
/* foreach ($defaults as $key => $val) {
if (!is_numeric($key) && !isset($url[$key])) {
$url[$key] = $val;
}
}*/
ksort($defaults);
ksort($url);
if ($defaults == $url) {
@ -522,21 +514,6 @@ class Router extends Overloadable {
} else {
return false;
}
/*if (!empty($diffs)) {
if (isset($route[3]['controller']) && in_array('controller', $diffed)) {
return false;
}
if (isset($route[3]['action']) && in_array('action', $diffed)) {
return false;
}
}*/
//$required = array_diff(array_diff($route[2], array_keys($route[3])), array_keys($url));
/*sort($required);
if (!empty($required)) {
return false;
}*/
if(!empty($route[4])){
foreach ($route[4] as $key => $reg) {
if (isset($url[$key]) && !preg_match('/' . $reg . '/', $url[$key])) {
@ -544,8 +521,6 @@ class Router extends Overloadable {
}
}
}
//$out = str_replace(array('/bare', '/*', '/ajax'), '', $route[0]);
return array(Router::__mapRoute($route, $url), $url);
}
/**
@ -567,7 +542,7 @@ class Router extends Overloadable {
} else {
$out = $route[0] . $params['pass'];
}
foreach ($route[2] as $key) {
$out = str_replace(':' . $key, $params[$key], $out);
unset($params[$key]);

View file

@ -246,10 +246,18 @@ class HtmlHelper extends AppHelper {
* @return string An <a /> element.
*/
function link($title, $url = null, $htmlAttributes = array(), $confirmMessage = false, $escapeTitle = true) {
if ($escapeTitle) {
$title = htmlspecialchars($title, ENT_QUOTES);
if($url !== null) {
$url = $this->url($url);
} else {
$url = $this->url($title);
$title = $url;
$escapeTitle = false;
}
if($escapeTitle === true) {
$title = htmlspecialchars($title, ENT_QUOTES);
} else if (is_string($escapeTitle)) {
$title = htmlentities($title, $escapeTitle);
}
$url = $url ? $url : $title;
if ($confirmMessage) {
$confirmMessage = htmlspecialchars($confirmMessage, ENT_NOQUOTES);
@ -258,7 +266,7 @@ class HtmlHelper extends AppHelper {
$htmlAttributes['onclick'] = "return confirm('{$confirmMessage}');";
}
$output = sprintf($this->tags['link'], $this->url($url), $this->_parseAttributes($htmlAttributes), $title);
$output = sprintf($this->tags['link'], $url, $this->_parseAttributes($htmlAttributes), $title);
return $this->output($output);
}
/**