Laravel 参数数量不同的路由
Laravel Routing with different amount of paramenters
我正在尝试通过以下途径完成控制我的功能:
Route::get('tri/{uniquename}/photos/gallery/{pic}', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
Route::get('tri/{uniquename}/{tab}/{filter}/', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
Route::get('tri/{uniquename}/{tab}/', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
我知道,我可以将路线 2 和路线 3 合并到
Route::get('tri/{uniquename}/{tab}/{filter?}/', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
但这不是我的问题。
我的函数如下所示(只有相关代码):
public function thisevent($uniquename, $tab="main", $filter="",$pic=""){
if($pic!=""){
$tab = "photos";
}
.....
}
如果我像这样请求 URL,该函数不会检测 $pic 参数:
http://dev.hobbyathletes.com/tri/Ocean-Lava-Lancerote-Triathlon-2014/photos/gallery/6
我做错了什么?
这是对的:
Route::get('tri/{uniquename}/{photos}/{gallery}/{pic}', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
在你的代码中 Laravel 认为你有两个参数并且 $tab 参数将是 $pic
我正在尝试通过以下途径完成控制我的功能:
Route::get('tri/{uniquename}/photos/gallery/{pic}', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
Route::get('tri/{uniquename}/{tab}/{filter}/', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
Route::get('tri/{uniquename}/{tab}/', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
我知道,我可以将路线 2 和路线 3 合并到
Route::get('tri/{uniquename}/{tab}/{filter?}/', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
但这不是我的问题。
我的函数如下所示(只有相关代码):
public function thisevent($uniquename, $tab="main", $filter="",$pic=""){
if($pic!=""){
$tab = "photos";
}
.....
}
如果我像这样请求 URL,该函数不会检测 $pic 参数:
http://dev.hobbyathletes.com/tri/Ocean-Lava-Lancerote-Triathlon-2014/photos/gallery/6
我做错了什么?
这是对的:
Route::get('tri/{uniquename}/{photos}/{gallery}/{pic}', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
在你的代码中 Laravel 认为你有两个参数并且 $tab 参数将是 $pic