Laravel4路由模式错误

编程入门 行业动态 更新时间:2024-10-18 03:34:52
本文介绍了Laravel4路由模式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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路由模式错误

本文发布于:2023-10-31 13:21:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546204.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路由   错误   模式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!