开发者

Kohana v3 routes - multiple optional parameters

开发者 https://www.devze.com 2023-01-18 07:30 出处:网络
I\'m setting up a search system which has urls eg. all parameters are optional and there are 15 possible params in total

I'm setting up a search system which has urls eg. all parameters are optional and there are 15 possible params in total

http://example.com/search/key1-value/key2-value/key3-value/key13-value/key15-value

Is there a better way to set up the route than this?

Ro开发者_Go百科ute::set('search', 'search(/<param1>(/<param2>(/<param3>(/<param4>(/<param5>(/<param6>(/<param7>(/<param8>(/<param9>(/<param10>(/<param11>(/<param12>(/<param13>(/<param14>(/<param15>)))))))))))))))')
        ->defaults(array(
        'controller' => 'search',
        'action'     => 'index',
));

I would then test for them in the controller and parse them to a neat array. Is there any way to specify a route with any number of optional /key-value/ parameters?


EDIT

I noticed the request object has a nice parameter array already -- this leads me back to the Route::set question.. is there a way to phrase it allowing any number of parameters without the ugly ...(/<param14>(/<param15>))))))))... nesting?


No.

PS: someone can say again that short answers are bad, but there is nothing to say more: No, there is no such way.


Route::set('search', 'search(/<params>/)',array('params'=>'\.*'))
        ->defaults(array(
        'controller' => 'search',
        'action'     => 'index',
));

tried?

0

精彩评论

暂无评论...
验证码 换一张
取 消