Kohana v3 路由 - 多个可选参数
我正在建立一个具有网址的搜索系统,例如。所有参数都是可选的,总共有 15 个可能的参数
http://example.com/search/key1-value/key2-value/key3-value/key13-value/key15-value
有没有比这更好的方法来设置路由?
Route::set('search', 'search(/<param1>(/<param2>(/<param3>(/<param4>(/<param5>(/<param6>(/<param7>(/<param8>(/<param9>(/<param10>(/<param11>(/<param12>(/<param13>(/<param14>(/<param15>)))))))))))))))')
->defaults(array(
'controller' => 'search',
'action' => 'index',
));
然后我会在控制器中测试它们并将它们解析为一个整齐的数组。有没有办法指定具有任意数量可选/键值/参数的路由?
编辑
我注意到请求对象已经有一个很好的参数数组——这让我回到了 Route::set 问题..有没有一种方法可以表达它,允许任意数量的参数,而无需丑陋的 ...(/
嵌套?
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?
Route::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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不。
PS:有人可能会再说一遍,简短的答案不好,但没有什么可说的:不,没有这样的方法。
No.
PS: someone can say again that short answers are bad, but there is nothing to say more: No, there is no such way.
尝试过吗?
tried?