Re: Is it possible to make an argument in a method controller to be optional?

falmp | 3 years ago | parent

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?



KevBurnsJr | 3 years ago

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.

reply



Welcome KrisJordan!

Web: http://www.krisjordan.com/

Location: North Carolina

Edit Profile