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

How to get the url parameter


Go to End


7 Posts   5307 Views

Avatar
px

Community Member, 10 Posts

16 March 2010 at 8:47pm

Hi! This might seem a little dumb question but I would just like to know how to get the URL Parameter of a certain site.
For example, I have this url:

http://www.mysite.com/forum/thread-one

What i want is to get the forum AND the thread-one parameter.

Any ideas?

Thanks! :)

Avatar
bummzack

Community Member, 904 Posts

16 March 2010 at 9:50pm

Edited: 16/03/2010 9:51pm

Hi

The first part of the URL (forum) is the URLSegment (you can get it using $this->URLSegment). The second part (thread-one) is the action. To access it use:

$action = Director::urlParam('Action');

Avatar
px

Community Member, 10 Posts

16 March 2010 at 9:55pm

Edited: 16/03/2010 9:56pm

hi! I tried it and I dump it to see if it shows a value but unfortunately, I get a NULL value :'(

var_dump(Director::urlParam('Action'));
exit();

result is NULL

Avatar
bummzack

Community Member, 904 Posts

16 March 2010 at 10:22pm

Where in your code is that dump statement?

Avatar
px

Community Member, 10 Posts

16 March 2010 at 10:46pm

Edited: 16/03/2010 10:47pm

In my widget controller. In this method:

function UserReviewsCommentFormStepOne() {
$URLParams = Director::urlParam('Action');
//$Segment = $URLParams['Action'];
//$a = new HTTPRequest();

var_dump($URLParams);
exit();
Session::clear('StepOneData');
$fields = new FieldSet(
new TextareaField("Pros","What did you like about this room?"),
new TextareaField("Cons","What did you not like in this room?"),
new OptionsetField("RecommendRoom",'Do you recommend this room?',array(
'Y'=>'Yes',
'N'=>'No'
),'Y'
)
);

$actions = new FieldSet(new FormAction('doUserReviewsCommentFormStepOne', 'next'));
$validator=new RequiredFields('Pros','Cons');
$form = new Form($this, 'doUserReviewsCommentFormStepOne', $fields, $actions);

return $form;
}

Also, I added a rule in my_config file for the thing that you said occur.
Something like this:

Director::addRules( 100, array(
'reviews/$Action' => 'UserReviewsWidget_Controller'
));

Avatar
bummzack

Community Member, 904 Posts

17 March 2010 at 12:15am

Hmm I never heard of a Widget Controller. I always thought Widgets don't have a controller themselves.
Accessing the Action is certainly possible in a Page-Controller, can't help you with widgets though. Sorry.
Maybe somebody else can give some pointers?

Avatar
px

Community Member, 10 Posts

17 March 2010 at 3:58am

no no...I'm wrong. it's page controller actually