我正在尝试通过以下路线完成控制我的功能:
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
我在这里做错了什么?
答案 0 :(得分:0)
这是对的:
Route::get('tri/{uniquename}/{photos}/{gallery}/{pic}', array( 'as' => 'sportevent', 'uses' => 'SporteventController@thisevent'));
在你的代码中,Laravel认为你有两个参数,而$ tab参数将是$ pic