Currently I have:
/**
* !Route GET, $test
*/
function index($test = 'default') {}
Which doesn't work. If I try to access the controller with no parameters, I get a "Resource does not exist" exception.
I have managed to do the optional arguments by looking closely to the routes tutorial. :)
My question below is still up though. Would it be possible to define a wildcard on the routes and then manage the following parameters using the Request resourceParts? Example:
!Route GET, /list/*
It seems the only available option is using the good old query strings.
Great suggestion. I've come across one point where it would have been nice to be able to 'consume' the rest of a URL to a variable.
I agree this is interesting behavior. Not sure what the best syntax will be. We'll want to pass the remainder of the URL matched to the controller method.
Shouldn't complicate the routing mechanisms too much.
And while we are at it, what about arbitrary number of arguments?
I'm trying to build a grid with several optional filters, in the URL I need to pass the column name to sort, the order (ASC or DESC), number of results per page, page requested, column name of filter 1, column name of filter2, etc. Something like this:
/list/sort/$field/order/$order/number/$number/page/$page/filter1/$filter1/filter2/$filter2
It seems I don't have this kind of freedom: create a route /list/ and then just get the named parameters, using default values if not presented (order of parameters ideally would not matter too).
Is there a way or do I need to use another delimiter instead of / and parse the parameters myself?
The URL ought to designate the resource, and the parameters ought to modify to the representation.
/groups/list?sort=field&order=desc&number=10
/groups/list?sort=field&order=desc&number=20
In each case you are asking for the same resource (a list of groups), but you are asking for a different representation of that resource (10 at a time or 20 at a time).
To me, this is the split between what belongs in the URL and what belongs in the parameters.