小编Hom*_*ice的帖子

具有任意数量的URL段的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?

php url-routing laravel laravel-4

1
推荐指数
1
解决办法
1792
查看次数

标签 统计

laravel ×1

laravel-4 ×1

php ×1

url-routing ×1