2015-03-13 65 views
1

我想要做的是設置它,以便用戶可以去「/項目/索引」(「/」是路線的C),但我不太確定如何做到這一點在laravel?Laravel子目錄視圖

我目前有:

路由:

Route::get('project.index', array('as' => 'project/index', 'uses' => '[email protected]'));

路由

另外:

View::addLocation('project'); //Project View View::addNamespace('project', 'project');

在我的項目負責人:

public function indexPage() 
    { 
     return View::make('index', array('pageTitle' => 'Project Index')); 
    } 

有什麼想法?提前致謝。

PS:這是Laravel 4

回答

1

你有你的路由有點不對勁。請嘗試以下

Route::get('project/index', ['as' => 'project.index', 'uses' => '[email protected]']); 

所以第一個參數爲Route::get()功能應該是用戶訪問例如http://example.com/project/index的URL。提供的數組中的as鍵是您給路由的名稱。

通過爲路由指定一個名稱,您可以在整個應用程序中使用該名稱,而不是使用用戶訪問的網址。例如,您可能要生成一個鏈接到你的路線

<a href="{{ route('project.index') ">Link</a> 

這將產生一個鏈接到http://example.com/project/index。如果您希望在不改變整個視圖文件中的大量鏈接的情況下更改URL,這可以方便將來使用。

Route::get('foobar/index', ['as' => 'project.index', 'uses' => '[email protected]']); 

通過route('project/index')生成的URL現在是http://example.com/foobar/index

結帳路由文檔以獲取更多信息http://laravel.com/docs/4.2/routing

+0

輝煌!你幫了我很多!先生+1。 – Jarkerwastaken 2015-03-13 20:11:33