fuelphp-storage / fuelphp

FuelPHP framework
http://fuelphp.com
MIT License
274 stars 57 forks source link

Array parameter routing (idea) #38

Open emlynwest opened 11 years ago

emlynwest commented 11 years ago

The idea is to be able to have a "match many" parameter when defining routes. This would allow the ability to pass any number of segments as an array to an action.

Example: Define a route to match controller/action/names/[]/foo/bar where the [] would be a place-holder marker that matches any number of segments until the one after it is matched (in this case foo).

This would then be passed to the action like so:

public function action_action($names, $foo, $bar){}

$names would then be an array populated with anything that is found between the names and foo segment, or an empty array if none where matched.

A route such as controller/action/names/tom/dick/harry/foo/bar would pass the parameters below to the action.

$names = array('tom', 'dick', 'harry');
$foo = 'foo';
$bar = 'bar';

This could then also work with multiple array segments: controller/action/names/[]/ages/[] to pass multiple arrays to the action.

WanWizard commented 11 years ago

@FrenkyNet Is this supported by fuelphp/routing ?

WanWizard commented 10 years ago

@FrenkyNet ping?

frankdejonge commented 10 years ago

@WanWizard this isn't supported, I wouldn't know of any way to map this to an array though. :confused:

WanWizard commented 10 years ago

Thought so.

Possible option: there is already the possibility for named parameters, right. If would not be to difficult to implement that if a name occurs multiple times, it's stored in an array, so you can define controller/action/names/names/names/ages/.... That should not be that difficult.

Challenge is when, as Steve mentioned, the number of names is variable.

Alteratively you could define the named parameter as an array like so: controller/action/names[]/ages, which basically means to glob segments into $names until you get to a segment called "ages"...