【发布时间】:2014-02-14 18:54:19
【问题描述】:
我有这个带有可选参数的路由:
Route::get('{id}/results/subject/{subject_id}/{step_id?}', array('as' =>'test', 'uses' => '\Controllers\TestController@Show'));
我在我的 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\TestController@Show', 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\TestController@Show'));
但两者都不起作用。
【问题讨论】:
标签: php laravel routing optional-parameters