douchui3933 2013-10-26 15:16
浏览 39

Laravel4路由模式错误

I´m using laravel 4 for a cms project, and i´m having some problems with my routes...

These are my current 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');

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.

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.

  • 写回答

1条回答 默认 最新

  • duanleixun2439 2013-10-26 15:41
    关注
    Route::resource('/user', 'UserController@index');
    Route::resource('/user/{route}', 'UserController');
    

    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):

    Take a look at the table called Actions Handled By Resource Controller

    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'))
    

    As a summary, Route::resource enables you quick CRUD RESTful access.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。