从URL段映射参数
问题描述:
URL: example.com/catalog/product/sort/pd.name/order/desc
I'm building out some custom routing. When exploding this url string I get an array that looks like so:
Array
(
[0] => catalog
[1] => product
[2] => sort
[3] => pd.name
[4] => order
[5] => desc
)
Key 0 and 1 is my controller. If my array was an odd number, then key 2 would be the method. Everything else needs to be set into my request service like so:
Request::set('sort', 'pd.name');
Request::set('order', 'desc');
I'm sure there must be a simple, elegant way to do this, but I'm not seeing it.
答
How about..
$controller = array_pop($array);
$controller2 = array_pop($array);
for($i=0;$i<=count($array),$i+2){
Request::set($array[$i],$array[$i+1]);
}