2013-09-23 59 views
0

爲什麼出錯這種簡單的命名路由擲錯誤與命名的路由

Route::get('/', array('as' => 'dashboard', function() 
{ 
    return View::make('hello'); 
})); 

我也帶控制器,而不是回調,但始終不變的測試,錯誤的是:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException 

我使用PHP 5.4.x測試代碼,但我不認爲它與PHP相關,我錯過了什麼?

+0

你acessing通過'http://本地主機/'? –

+0

我配置了一個專用的VirtuaHost'http:// example.dev' –

+0

剛剛編輯了答案。嘗試一下。 –

回答

0

這條路線:

Route::get('/', array('as' => 'dashboard', function() 
{ 
    return View::make('hello'); 
})); 

將定義這個網址爲您提供:

http://example.dev/ 

但要創建一個鏈接到這條路線,你必須

URL::route('dashboard'); 

如果您需要通過

012訪問您的儀表板

你必須定義

Route::get('dashboard', array('as' => 'dashboard', function() 
{ 
    return View::make('hello'); 
})); 
+0

在發佈此類問題之前,我必須更多地關注文檔[http://laravel.com/docs/routing#named-routes](http://laravel.com/docs/routing#named-routes) 。感謝您的解釋。 –