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.

Archive /

Our old forums are still available as a read-only archive.

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

urlParams


Go to End


6 Posts   3486 Views

Avatar
dio5

Community Member, 501 Posts

3 October 2007 at 10:04am

Hi,

could someone explain the use of urlParams to me? I've been looking through the docu but can't find it.

It looks like it's being used as $_GET or $_POST, but don't know the details.

Anyone?

Thanks!

Avatar
Sean

Forum Moderator, 922 Posts

3 October 2007 at 11:05am

Edited: 03/10/2007 11:08am

More specifically, what are you referring to?

urlParams is used like $this->urlParams['Action'], which produces 'myaction' from mysite.com/home/myaction

So, you can then make a method myaction() on the controller you called that action from. This method is proceessed whenever the action is called.

You can use Debug::show($this->urlParams) on a controller to find out what you've got available based on your URL. It's extremely useful for parameters like mysite.com/news/category/1. In this case 'category' is an action, and 1 is an ID - urlParams['Action'] and urlParams['ID'] appropriately

Does this answer some questions?

TODO: Documentation on urlParams ;-)

Sean

Avatar
dio5

Community Member, 501 Posts

3 October 2007 at 11:13am

Edited: 03/10/2007 11:21am

Yes, that was more or less what I was searching for.

I was looking for how to get that 'number' out of the url in mysite.com/news/category/1.

Is any number coming after an action automatically referred to as urlParams['ID'], or do I have to set it as an urlParam before I can access it as urlParam (... this probly sounds weird :-) )
?
Got it... it's automatic!

Avatar
dio5

Community Member, 501 Posts

3 October 2007 at 11:20am

Ok, great! Got it now.. :-)

Avatar
dio5

Community Member, 501 Posts

5 October 2007 at 3:52am

Hey,

what if I wanted this:

mysite.com/news/category/nature

Could I still access 'nature' as an URLParam['ID'] or would that mean nature has to be an action too?

I suppose I could make it 'number'-based, but for simplicity and SEO's sake it would be better to have the names...

Any ideas?

Avatar
Matt

Community Member, 86 Posts

12 October 2007 at 9:15am

Nope, ID is anything in that place - it doesn't necessarily have to be a number.