mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT: Updated SiteTree linking methods to generate nested URLs.
MINOR: Updated ContentController->Link() to force links generated by a controller to always be returned in their full form. From: Andrew Short <andrewjshort@gmail.com> git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@88476 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
55408946a6
commit
3599a105fd
20
core/control/ContentController.php
Normal file → Executable file
20
core/control/ContentController.php
Normal file → Executable file
@ -43,20 +43,14 @@ class ContentController extends Controller {
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the link to this controller, but force the expanded link to be returned so that form methods and
|
||||||
|
* similar will function properly.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
public function Link($action = null) {
|
public function Link($action = null) {
|
||||||
return Director::baseURL() . $this->RelativeLink($action);
|
return $this->data()->Link(($action ? $action : true));
|
||||||
}
|
|
||||||
public function RelativeLink($action = null) {
|
|
||||||
|
|
||||||
if($this->URLSegment){
|
|
||||||
if($action == "index") $action = "";
|
|
||||||
|
|
||||||
// '&' in a URL is apparently naughty
|
|
||||||
$action = preg_replace('/&/', '&', $action);
|
|
||||||
return $this->URLSegment . "/$action";
|
|
||||||
} else {
|
|
||||||
user_error("ContentController::RelativeLink() No URLSegment given on a '$this->class' object. Perhaps you should overload it?", E_USER_WARNING);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------//
|
//----------------------------------------------------------------------------------//
|
||||||
|
45
core/model/SiteTree.php
Normal file → Executable file
45
core/model/SiteTree.php
Normal file → Executable file
@ -264,29 +264,46 @@ class SiteTree extends DataObject implements PermissionProvider,i18nEntityProvid
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the URL for this page.
|
* Return the link for this {@link SiteTree} object, with the {@link Director::baseURL()} included.
|
||||||
*
|
*
|
||||||
* @param string $action An action to include in the link
|
* @param string $action
|
||||||
* @return string The URL for this page
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function Link($action = null) {
|
public function Link($action = null) {
|
||||||
if($action == "index") {
|
return Controller::join_links(Director::baseURL(), $this->RelativeLink($action));
|
||||||
$action = "";
|
|
||||||
}
|
|
||||||
if($this->URLSegment == 'home' && !$action) return Director::baseURL();
|
|
||||||
else return Director::baseURL() . $this->URLSegment . "/$action";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the absolute URL for this page by stage
|
* Get the absolute URL for this page, including protocol and host.
|
||||||
|
*
|
||||||
|
* @param string $action
|
||||||
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function AbsoluteLink() {
|
public function AbsoluteLink($action = null) {
|
||||||
if($this->hasMethod('alternateAbsoluteLink')) return $this->alternateAbsoluteLink();
|
if($this->hasMethod('alternateAbsoluteLink')) {
|
||||||
else return Director::absoluteURL($this->Link());
|
return $this->alternateAbsoluteLink($action);
|
||||||
|
} else {
|
||||||
|
return Director::absoluteURL($this->Link($action));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the link for this {@link SiteTree} object relative to the SilverStripe root.
|
||||||
|
*
|
||||||
|
* @param string $action
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function RelativeLink($action = null) {
|
||||||
|
$action = str_replace('&', '&', $action);
|
||||||
|
|
||||||
|
if($this->ParentID && self::nested_urls()) {
|
||||||
|
$base = $this->Parent()->RelativeLink($this->URLSegment);
|
||||||
|
} else {
|
||||||
|
$base = $this->URLSegment;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "$base/$action";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns link/current, depending on whether you're on the current page.
|
* Returns link/current, depending on whether you're on the current page.
|
||||||
|
Loading…
Reference in New Issue
Block a user