Hom*_*ice 1 php url-routing laravel laravel-4
我有一个L3应用程序,我正在尝试移植到L4.在L3版本中,我的一条路线是
Route::get('/(:any)/(:all?)', etc...
Run Code Online (Sandbox Code Playgroud)
这允许我处理任意数量的URL段,例如:
/contact_page
/store_category
/store_category/shirts_category
/store_category/shirts_category/specific_shirt_page
/an/arbitrary/number/of/nested/categories
Run Code Online (Sandbox Code Playgroud)
但是在L4中我无法弄清楚如何模仿(:all?)的功能
以下代码有效:
Route::get('/{arg1?}/{arg2?}/{arg3?}', function($arg1='home', $arg2, $arg3)
{
//do something
});
Run Code Online (Sandbox Code Playgroud)
所以我可以添加大量的可选参数(超过我认为在实际使用中我会需要的),但这不是很优雅.
在Laravel 4中是否有某种方法来定义可以响应任意数量的URL段的Route?
小智 11
您可以在路线中添加模式条件,例如:
Route::get('{any}/{args}', function($action, $args = null)
{
// do something like return print_r(explode('/', $args), true);
})->where('args', '(.*)');
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1792 次 |
最近记录: |