简体   繁体   English

获取所有路线,Laravel 4

[英]Get all routes, Laravel 4

What I want is just to use one controller at the moment which should handle every request that comes to my laravel 4 application. 我想要的只是使用一个控制器,它应该处理我的laravel 4应用程序的每个请求。 The problem is that none of the solutions on stackoverflow or elsewhere are working for me. 问题是stackoverflow或其他地方的解决方案都没有对我有用。

That's what i currently have: 这就是我现在拥有的:

Route::any('(.*)', function(){
  return View::make('hello');
});

Now when browsing to the page I get an error everytime saying: 现在浏览页面时我每次都会收到错误说:

Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException

Hope somebody could help me out! 希望有人能帮助我!

Regular expressions are set as requirements and not directly in the route. 正则表达式设置为要求,而不是直接在路径中。

Route::any('{all}', function($uri)
{
    return View::make('hello');
})->where('all', '.*');
Route::group(array('prefix' => '/', 'before' => 'MAKEYOUROWNFILTER'), function()
{

    // your routers after the / ....
});

// and in filters.php //并在filters.php中

Route::filter('MAKEYOUROWNFILTER', function()
{

    // do stuff or just
    return View::make('hello');

});

Extending on #Jason Lewis's answer to redirect to the root page: 扩展#Jason Lewis的重定向到根页面的答案:

Route::any('{all}', function($uri)
{
    return Redirect::to('/');
})->where('all', '.*');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM