传递许多可选参数以在Laravel 4中进行路由 [英] Pass many optional parameters to route in Laravel 4

查看:69
本文介绍了传递许多可选参数以在Laravel 4中进行路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要构建如下网址:

http://www.example.com/param1/param2/param3/.../paramN

在搜索页面中,用户通过任何可能的选项进行搜索,因此在Laravel中创建类似这样的URL会是这样的:

in a search page, user searchs by any possible options so making a URL like it in Laravel would be like this:

Route::get('{param1?}/{param2?}/{param3?}/.../{paramN?}', array( ... ) );

还有其他方法吗?或者,也许将/作为参数的一部分传递给它:

Is there any other way? Or maybe pass / as a part of parameter to have this:

low_range-1000/high_range-5000/weight-2/height-4/red/

因此,行上方只是要路由的一个参数.

so above line become just one parameter to route.

有什么帮助吗?

推荐答案

好,我找到了解决方案.只是为了节省别人的时间.

well, I found the solution. just to save others time.

Route::get('{param1}/{param2?}', array( ... ) )->where('param2', '.*');

此路由需要param1作为必需参数,而param2作为可选参数,可以包含任何字符,包括/.

this routes needs param1 as a required parameter, and param2 as an optional parameter which can contain any character includes /.

所以我可以将low_range-1000/high_range-5000/weight-2/height-4/red/作为param2传递.

so I can pass low_range-1000/high_range-5000/weight-2/height-4/red/ as param2.

这篇关于传递许多可选参数以在Laravel 4中进行路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆