我正在使用laravel 4进行cms项目,但是我的路线存在一些问题...
I´m using laravel 4 for a cms project, and i´m having some problems with my routes...
这是我目前的路线
Route::get('/', 'IndexController@showNews'); Route::get('/logout', 'UserController@logout'); Route::resource('/login', 'UserController'); Route::resource('/user', 'UserController@index'); Route::resource('/user/{route}', 'UserController'); // Routes that shows us the pages... Route::get('/{page}', 'IndexController@showPage'); Route::get('/{page}/{id}', 'IndexController@showPage');对于我的用户路由,我有一个自定义路由器,可以路由用户信息,这并不是一个真正的问题.但这一切都很好,但是当我尝试导航到"/test"时,Wich会链接到测试页面,这给了我这个错误.
To my user routes i have a custom router that routes the user information around, not really a problem. But all of that works great, but when i try to navigate to "/test" Wich would link to a test page, it gives me this error.
Route pattern "/user/{route}/{{route}}" cannot reference variable name "route" more than once.这取决于路由器的逻辑,我对laravel还是很陌生.我有办法解决这个问题吗?这是用户/路由和/route通配符之间的冲突.
It comes up to router logic, and i´m fairly new to laravel. Is there a way for me to work around this problem? It´s a collision between the user/route and the /route wildcards.
推荐答案Route::resource('/user', 'UserController@index'); Route::resource('/user/{route}', 'UserController');
问题是您正在使用Route::resource声明路由,而实际上您通过使用Route::resource声明了RESTful控制器,该控制器具有要由Laravel自动处理的动作表.您使用不正确.
The problem is that you are using Route::resource to declare the routes, while by using Route::resource you are actually declaring a RESTful controller with a table of actions to be handled by Laravel automatically. You are using it incorrectly.
请参见文档,以了解在后台处理了哪些路由(以及因此是冲突的根源):
See the docs to see which routes are handled in the background (and hence the source of the conflict):
看看名为资源控制器处理的操作
对于不在表中的任何路由处理程序,您将必须声明单独的路由.像这样:
For any route handler that is not within the table you will have to declare separate routes. Something like:
Route::get('foo/filter/{filterName}/{filterValue}', array('as'=>'filteredroute','uses'=>'FooController@filter'))作为总结,Route::resource使您可以快速 CRUD RESTful 访问.
As a summary, Route::resource enables you quick CRUD RESTful access.
更多推荐
Laravel4路由模式错误
发布评论