Laravel 4.2走错了路线

时间:2018-08-21 18:15:54

标签: php laravel laravel-4 routes laravel-routing

这是我正在访问的网址:http://example.com/hotel/expired

代替这条路线的好控制者

Route::get('/hotel/expired', ModuleLoader::load_controller(_ACCOUNT , 'redirectExpired'));

这是使用的路线:

Route::post('/hotel/search', 'HotelControllerB2C@search');

但是,如果我更改此/ hotel / session / expired的/ hotel / expired路线,则会使用正确的控制器

Route::any('/hotel/search/{dep_date}/{dep_code}/{ret_date}/{ages}', 'HotelControllerB2C@showSearch');
Route::any('/hotel/search/{dep_date}/{dep_code}/{ret_date}/{ages}/{property_type}', 'HotelControllerB2C@showSearch');
Route::post('/hotel/search', 'HotelControllerB2C@search');
Route::get('/hotel/detail/{index}', 'HotelControllerB2C@showDetail');
Route::post('/hotel/detail', 'HotelControllerB2C@detail');
Route::get('/hotel/{sid}', ModuleLoader::load_controller(_ACCOUNT , 'showPreviousSearch'));
Route::any('/hotel/confirmation/{url}', ModuleLoader::load_controller(_ACCOUNT , 'confirmation'));
Route::get('/hotel/expired', ModuleLoader::load_controller(_ACCOUNT , 'redirectExpired'));

为什么laravel认为/ hotel / expired是/ hotel / search?一种使用post方法,另一种使用get方法。

1 个答案:

答案 0 :(得分:0)

按定义的顺序解析幼虫中的路由。之后,您有/hotel/{sid}/hotel/expired,因此在这种情况下:

/hotel/anything => goes to /hotel/{sid} route
/hotel/expired => also goes to /hotel/{sid} route

为避免这种情况,您应该首先定义最具体的路线,然后再定义更一般的路线,因此在您的情况下,您应该输入以下行:

Route::get('/hotel/expired', ModuleLoader::load_controller(_ACCOUNT , 'redirectExpired'));

之前

Route::get('/hotel/{sid}', ModuleLoader::load_controller(_ACCOUNT , 'showPreviousSearch'));