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

Retrieve URL query string


Go to End


2 Posts   1661 Views

Avatar
hschillig

Community Member, 5 Posts

9 October 2014 at 6:45am

Hello. This is my first time using SilverStripe. I'm going through the tutorial and I'm on the browser poll section right now. However, I was trying to add my own thing to try and get the hang of things myself, a small addition.

My view calls this on the homepage:

Results: $ShowResults

In my controller, I have this method (the controller and everything is hooked up correctly since the poll is working):

public function ShowResults()
{
	return ($this->request->param('request') == 'yes' ? 'its yes' : 'none');
	// return ($this->request->param('request') == 'yes' ? true : false);
}

I was just trying to get something to spit out. No matter if /?request=yes is appended to the url or not, it keeps giving me back the string 'none'. When it should say 'yes' if it's equal to yes.

Any help would be greatly appreciated. Thank you!

Avatar
kinglozzer

Community Member, 187 Posts

9 October 2014 at 9:16pm

Hi,

If you’re appending a query string, the method you’ll need to use is getVar:

return ($this->request->getVar('request') == 'yes' ? 'its yes' : 'none');

param() is for fetching named parameters (built in ones are “Action” and “ID”): see the “routing” example http://doc.silverstripe.org/framework/en/topics/controller

Hope this helps,

Loz