2013-04-23 101 views
8

我想要的只是使用一個控制器,應該處理每個請求到我的laravel 4應用程序。問題是沒有任何解決方案在stackoverflow或其他地方爲我工作。瀏覽的網頁,我得到一個錯誤,每次說的時候獲取所有路線,Laravel 4

Route::any('(.*)', function(){ 
    return View::make('hello'); 
}); 

現在:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException 

希望有人可以幫助我

這就是我現在有!

回答

49

正則表達式被設置爲需求,而不是直接在路由中。

Route::any('{all}', function($uri) 
{ 
    return View::make('hello'); 
})->where('all', '.*'); 
+0

哇!非常感謝! – 2013-04-24 06:16:49

+0

Thx。如何在這裏使用「TestController」而不是直接返回視圖? – Danzzz 2013-05-26 08:13:01

+2

同樣道理,但不是使用閉包作爲第二個參數,你可以做'Route :: any('{all}','TestController @ method');' – 2013-05-27 02:52:14

1
Route::group(array('prefix' => '/', 'before' => 'MAKEYOUROWNFILTER'), function() 
{ 

    // your routers after the/.... 
}); 
//

和filters.php

Route::filter('MAKEYOUROWNFILTER', function() 
{ 

    // do stuff or just 
    return View::make('hello'); 

}); 
0

擴展上#Jason劉易斯的回答重定向到根頁:

Route::any('{all}', function($uri) 
{ 
    return Redirect::to('/'); 
})->where('all', '.*');