2014-02-14 67 views
0

我有一個可選的參數,這條路線:Laravel 4命名路由可選PARAMATERS

Route::get('{id}/results/subject/{subject_id}/{step_id?}', array('as' =>'test', 'uses' => '\Controllers\[email protected]')); 

,我得到這個在我的TestController

function Show($id, $subject_id, $step_id){ 
//Some stuff 
} 

我想一個默認值屬性我選step_id參數就像here。如果我沒有給出一個默認值,我的控制器就會失去一個參數錯誤。

我已經試過

Route::get('{id}/results/subject/{subject_id}/{step_id?}', array('as' =>'test', 'uses' => '\Controllers\[email protected]', function($step_id = '3'){return $step_id}); 

Route::get('{id}/results/subject/{subject_id}/{step_id?}',function($step_id = '3'){return $step_id}, array('as' =>'test', 'uses' => '\Controllers\[email protected]')); 

但兩者都沒有工作。

回答

1

只需在你的功能中設置默認值就可以了。

function ShowFactorRat($id, $subject_id, $step_id="default value here"){ 
//Some stuff 
} 
+0

謝謝。我將在10分鐘內接受。 – Wistar