2015-03-13 64 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