I have website url like below, and I would like to get full url so that i can pass to social network for sharing purpose
i.e. www.mysite.com/projects?tab=2
I tried AbsoluteLink but '?tab=2' is left out.
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
I have website url like below, and I would like to get full url so that i can pass to social network for sharing purpose
i.e. www.mysite.com/projects?tab=2
I tried AbsoluteLink but '?tab=2' is left out.
Hi Thomas,
You can use SS_HTTPRequest::getURL() and pass true as the parameter to get the current URL including get vars.
In a Controller, this’d be:
$this->request->getURL(true);
Hope this helps.
Loz
Hello King
I tried SS_HTTPRequest::getURL(true) but return below error
Non-static method SS_HTTPRequest::getURL() should not be called statically, assuming $this from incompatible context
the code reside in DataExtension of SiteTree.
Hi Thomas,
getURL() isn’t a static method, so you can’t call it directly like that. You should be able to use:
$this->owner->request->getURL(true);
in your extension (untested). If that doesn’t work, you might be able to use:
Controller::curr()->request->getURL(true);
Loz
yes Luz, you are right getURL() isn’t a static method,
Controller::curr()->request->getURL(true); returned projects?tab=2 so I appended with Director::absoluteBaseURL()
Director::absoluteBaseURL().Controller::curr()->request->getURL(true)
Thank you for your help.
You are awesome Luz.