没有参数的Laravel基本路由 - NotFoundHttpException

时间:2015-02-12 15:47:04

标签: symfony laravel laravel-4

我有一个自定义路由控制器,在返回视图之前检查数据库。据说我除了第一个之外没有将任何参数传递给该控制器而且永远不会。有没有办法阻止laravel期待一个参数?我收到此错误:

mydomain/login ----工作正常

mydomain/login/sometext - 引发错误

  

" Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException"    /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php

routes.php文件

Route::get('/', function(){return View::make('main.landing');});
Route::get('/{path}', array('uses' => 'RouteController@index'));

然后在我的RouteController中,我使用$ path和query数据库检查路由是否存在,然后显示自定义视图。

任何帮助将不胜感激! 谢谢!

2 个答案:

答案 0 :(得分:3)

您需要在路由器参数中指定要允许斜杠的路由器。你可以这样做:

Route::get('/{path}', array('uses' => 'RouteController@index'))->where('path', '(.*)');

这将允许任何角色。

答案 1 :(得分:1)

默认路由参数不接受斜杠。您需要明确允许路径参数中的任何字符:

Route::get('/{path}', array('uses' => 'RouteController@index'))
    ->where('path', '(.*)');