17691 Posts in 4607 Topics by 2180 members
General Questions
SilverStripe Forums » General Questions » How to get the url parameter
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba
|
Page:
1
|
Go to End | |
| Author | Topic: | 1845 Views |
-
How to get the url parameter

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!
-
Re: How to get the url parameter

16 March 2010 at 9:50pm Last edited: 16 March 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');
-
Re: How to get the url parameter

16 March 2010 at 9:55pm Last edited: 16 March 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
-
Re: How to get the url parameter

16 March 2010 at 10:22pm
Where in your code is that dump statement?
-
Re: How to get the url parameter

16 March 2010 at 10:46pm Last edited: 16 March 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'
)); -
Re: How to get the url parameter

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? -
Re: How to get the url parameter

17 March 2010 at 3:58am
no no...I'm wrong. it's page controller actually
| 1845 Views | ||
|
Page:
1
|
Go to Top |


