Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

return the entire request url using silverstripe


Go to End


5 Posts   1610 Views

Avatar
thomas.paulson

Community Member, 107 Posts

2 September 2014 at 3:22am

Edited: 02/09/2014 4:38am

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.

Avatar
kinglozzer

Community Member, 187 Posts

2 September 2014 at 4:22am

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

Avatar
thomas.paulson

Community Member, 107 Posts

2 September 2014 at 4:35am

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.

Avatar
kinglozzer

Community Member, 187 Posts

2 September 2014 at 10:29pm

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

Avatar
thomas.paulson

Community Member, 107 Posts

3 September 2014 at 12:32am

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.