2013-01-18 38 views
1

我有一個L3應用程序,我試圖移植到L4。在L3的版本,我的途徑之一是Laravel 4路由與任意數量的URL段

Route::get('/(:any)/(:all?)', etc... 

這讓我來處理URL段的任意數字,例如:

/contact_page 
/store_category 
/store_category/shirts_category 
/store_category/shirts_category/specific_shirt_page 
/an/arbitrary/number/of/nested/categories 

但在L4我無法弄清楚如何效仿功能(?:所有)

下面的代碼工作:

Route::get('/{arg1?}/{arg2?}/{arg3?}', function($arg1='home', $arg2, $arg3) 
{ 
    //do something 
}); 

所以,我可以補充大量可選參數(超過我想我在真實世界中使用時所需要的),但這不是很優雅。

Laravel 4中是否有某種方法可以定義可響應任意數量URL段的Route?

回答

11

您可以添加一個模式條件,你的路線,例:

Route::get('{any}/{args}', function($action, $args = null) 
{ 
    // do something like return print_r(explode('/', $args), true); 
})->where('args', '(.*)'); 
+0

輝煌!非常感謝。 – HomeSlice

+0

不錯的想法:) – motto