Allow querystrings in arguments passed to Controller::join_links()

Fix FormField::Link() to allow querystrings in the form's action


git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@61064 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2008-08-19 10:06:43 +00:00
parent 23d6fb8952
commit 292140897a
2 changed files with 12 additions and 4 deletions

View File

@ -458,16 +458,24 @@ class Controller extends RequestHandlingData {
/**
* Joins two link segments together, putting a slash between them if necessary.
* Use this for building the results of Link() methods.
*
* If either of the links have query strings, then they will be combined and put at the end of the resulting url.
*/
static function join_links() {
$args = func_get_args();
$result = array_shift($args);
$result = "";
$querystrings = array();
foreach($args as $arg) {
if(substr($result,-1) != '/' && $arg[0] != '/') $result .= "/$arg";
if(strpos($arg,'?') !== false) {
list($arg, $suffix) = explode('?',$arg,2);
$querystrings[] = $suffix;
}
if($result && substr($result,-1) != '/' && $arg[0] != '/') $result .= "/$arg";
else $result .= $arg;
}
if($querystrings) $result .= '?' . implode('&', $querystrings);
return $result;
}
}

View File

@ -74,7 +74,7 @@ class FormField extends RequestHandlingData {
* Return a Link to this field
*/
function Link() {
return $this->form->FormAction() . '/field/' . $this->name;
return Controller::join_links($this->form->FormAction(), 'field/' . $this->name);
}
/**