所以我已簽出 PHP - Routing with Parameters in Laravel 和 Laravel 4 mandatory parameters errorLaravel路由控制器,帶有強制參數
但使用的是什麼說 - 我似乎無法做一個簡單的路由不可能的,除非我不是瞭解如何過濾器/獲得/參數作品。
所以我想要做的是有一個路由URL顯示/ 2 其中顯示是一個行動和2是一個ID,但我想限制它只有數字。
我想
Route::get('displayproduct/(:num)','[email protected]');
Route::get('/', '[email protected]');
class SiteController extends BaseController {
public function index()
{
return "i'm with index";
}
public function display($id)
{
return $id;
}
}
的問題是,它拋出404 如果我使用
Route::get('displayproduct/{id}','[email protected]');
它將傳遞參數然而,URL可以是顯示/ ABC,它會通過參數。 我想僅限於數字。
我也不希望它是寧靜的,因爲索引我理想地想要混合這個控制器與不同的行動。
so(:num)(:any)以及所有不起作用的東西? – azngunit81
正確,所有約束都使用正則表達式完成,使用{id}將允許任何內容匹配。看看http://laravel.com/docs/routing#route-parameters – dragoon
tks - 代碼快樂需要更新他們的文檔 – azngunit81