我正在尝试做的是设置它以便用户可以转到“/ project / index”(“/”是路径ofc)但是我不太确定如何在laravel中执行此操作?
我现在有什么:
路由:
Route::get('project.index', array('as' => 'project/index', 'uses' => 'ProjectController@indexPage'));
同样在路由:
View::addLocation('project'); //Project View
View::addNamespace('project', 'project');
在我的项目控制器中:
public function indexPage()
{
return View::make('index', array('pageTitle' => 'Project Index'));
}
有什么想法吗?提前谢谢。
PS:这是Laravel 4
答案 0 :(得分:1)
你的路由有点不对劲。试试以下
Route::get('project/index', ['as' => 'project.index', 'uses' => 'ProjectController@index']);
因此,Route::get()
函数的第一个参数应该是用户正在访问的网址,例如http://example.com/project/index
。提供的数组中的as
键是您为路由提供的名称。
通过为路由指定名称,您可以在整个应用程序中使用此名称,而不是使用用户正在访问的URL。例如,您可能希望生成指向路线的链接
<a href="{{ route('project.index') ">Link</a>
这将生成指向http://example.com/project/index
的链接。如果您希望更改网址而不更改整个视图文件中的大量链接,这将在以后方便。
Route::get('foobar/index', ['as' => 'project.index', 'uses' => 'ProjectController@index']);
通过route('project/index')
生成的网址现在为http://example.com/foobar/index
查看路由文档以获取更多信息http://laravel.com/docs/4.2/routing