获取所有路由,Laravel 4
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16178426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get all routes, Laravel 4
提问by Andre Zimpel
What I want is just to use one controller at the moment which should handle every request that comes to my laravel 4 application. The problem is that none of the solutions on stackoverflow or elsewhere are working for me.
我现在想要的只是使用一个控制器来处理我的 laravel 4 应用程序的每个请求。问题是,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!
希望有人能帮帮我!
回答by Jason Lewis
Regular expressions are set as requirements and not directly in the route.
正则表达式被设置为要求,而不是直接在路由中。
Route::any('{all}', function($uri)
{
return View::make('hello');
})->where('all', '.*');
回答by mangas
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');
});
回答by Nasif Md. Tanjim
Extending on #Jason Lewis's answer to redirect to the root page:
扩展#Jason Lewis 对重定向到根页面的回答:
Route::any('{all}', function($uri)
{
return Redirect::to('/');
})->where('all', '.*');