SS URL rule templates

155 views
Skip to first unread message

webbower

unread,
Jan 22, 2010, 5:10:23 PM1/22/10
to SilverStripe Development
I see in some of the code calls to Director::add_rules() and the
$url_handlers stats in the Controller classes and I don't quite
understand all the syntax. I understand the standard $VarName but, for
example, in the Image_Uploader class, there are exclamation marks in
the rules. What are those for? Is there a page in the SS docs that
describes all the possible syntax items for making custom URL rules in
SS?

webbower

unread,
Jan 22, 2010, 5:38:35 PM1/22/10
to SilverStripe Development
I also see double forward slashes. What are those for?

Nicolaas Thiemen Francken - Sunny Side Up

unread,
Jan 22, 2010, 11:27:09 PM1/22/10
to silverst...@googlegroups.com
good question - I always wonder about those // as well ;-)

Andrew Short

unread,
Jan 22, 2010, 11:32:48 PM1/22/10
to silverst...@googlegroups.com
The double slashes are used to specify the shift point for the parser. When a rule is successfully matched it will consume the matched content up the the double slashes so it wont get matched by subsequent URL handlers.

The ! after a variable name means that the variable is required, and the rule wont match unless the variable is specified.

The best place to read about this is in the SS_HTTPRequest source - a lot of this isn't covered on the documentation wiki.

--
Andrew Short

Mark

unread,
Jan 23, 2010, 7:33:23 AM1/23/10
to silverst...@googlegroups.com
I wrote a simple explanation of this a while ago... it's less likely
people will run into the need to do raw mvc controllers, now that the
nested urls are actually part of the SS distro.

http://maetl.net/silverstripe-url-handling

should update to explain the // as well.

--
Mark Rickerby

dalesaurus

unread,
Jan 23, 2010, 1:51:48 PM1/23/10
to SilverStripe Development
I have added some of this to the wiki, would some of you mind fact-
checking my additions to be sure I've gotten them right? I went off
of the documentation in the current trunk code for HTTPRequest->match
().

http://doc.silverstripe.org/doku.php?id=controller

Andrew Short

unread,
Jan 23, 2010, 2:07:53 PM1/23/10
to silverst...@googlegroups.com
You got the bit on the shift point wrong - the entire rule is used to populate variables. The idea is that one URL can be matched by several sub-rules, traversing down a tree of controllers. When a controller matches part of the URL it will consume this. By default the entire matched segment is consumed and can't be matched in subsequent operations. What the double-slash shift point does is specify that the URL parts before the double slash will be consumed by the current rule, while the parts after the shift point will be left available for further sub-rules to match.

--
Andrew Short

dalesaurus

unread,
Jan 24, 2010, 12:40:12 PM1/24/10
to SilverStripe Development
I think I get the concept of the shift points, but would you be able
to provide an example of how a structure of such controllers would
look and how the traversal stops and hands off to the next? Is that
exclusive to nested urls in 2.4 (it doesn't appear so in the commit
log)?

There are two other parts I neglected and would appreciate any
clarifications on:
1. File Extensions
You can add a extension to intercept requests that would appear to be
to a file
'order/condiment/ketchup.jpg'
Can you add variables in this or would you use it for something like
applying controller code to the request? I could see this being
useful for intercepting static content requests and ferrying them on
to a CDN maybe?

2. Specifying Request Type
You can target a request type by prefacing the pattern with it like:
'GET order/$ID'
'PUT order/newfromfile'
What would be a practical case for this? Using PUT to accept a file
REST like and deal with it in your Controller code using fopen("php://
input", "r")?


Thanks for everyone's patience, this exercise has opened up a whole
lot of new functionality to my brain with SS. I'm excited to clarify
it at least on the wiki for others to pick up on.

Ingo Schommer

unread,
Jan 25, 2010, 1:01:30 AM1/25/10
to silverst...@googlegroups.com
On 25/01/2010, at 6:40 AM, dalesaurus wrote:

> 1. File Extensions
> You can add a extension to intercept requests that would appear to be
> to a file
> 'order/condiment/ketchup.jpg'
> Can you add variables in this or would you use it for something like
> applying controller code to the request? I could see this being
> useful for intercepting static content requests and ferrying them on
> to a CDN maybe?

The default .htacces doesn't allow you to do this at the moment,
we're considering removing this restriction (at the expense of
more server load for "non-PHP 404" requests: http://open.silverstripe.org/ticket/2958

dalesaurus

unread,
Feb 2, 2010, 3:41:03 PM2/2/10
to SilverStripe Development
Thanks Ingo,

Andrew can your or anyone else speak to the first part on how to
structure a cascading controllers with shift points, per below:


> would you be able
> to provide an example of how a structure of such controllers would
> look and how the traversal stops and hands off to the next? Is that
> exclusive to nested urls in 2.4 (it doesn't appear so in the commit log)?

Also anyone have thoughts on #2:


> 2. Specifying Request Type
> You can target a request type by prefacing the pattern with it like:
> 'GET order/$ID'
> 'PUT order/newfromfile'
> What would be a practical case for this? Using PUT to accept a file
> REST like and deal with it in your Controller code using fopen("php://
> input", "r")?


Thanks
-Dale

Mat Weir

unread,
Feb 2, 2010, 4:16:44 PM2/2/10
to silverst...@googlegroups.com
Request types are used in Form where POST and GET requests are handled as submissions.

I've done some development where I've overriden some Director rules which has broken the above and can't for the life of me work out how to get the Form to match POST and GET requests again.

It's a tricky subject, I'd like some more light shed on it too.

Cheers,

Mat Weir




--
You received this message because you are subscribed to the Google Groups "SilverStripe Development" group.
To post to this group, send email to silverst...@googlegroups.com.
To unsubscribe from this group, send email to silverstripe-d...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/silverstripe-dev?hl=en.


Reply all
Reply to author
Forward
0 new messages